Posts

Showing posts with the label Text

Android: Combining Text & Image On A Button Or ImageButton

Answer : For users who just want to put Background, Icon-Image and Text in one Button from different files: Set on a Button background, drawableTop/Bottom/Rigth/Left and padding attributes. <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/home_btn_test" android:drawableTop="@drawable/home_icon_test" android:textColor="#FFFFFF" android:id="@+id/ButtonTest" android:paddingTop="32sp" android:drawablePadding="-15sp" android:text="this is text"></Button> For more sophisticated arrangement you also can use RelativeLayout (or any other layout) and make it clickable. Tutorial: Great tutorial that covers both cases: http://izvornikod.com/Blog/tabid/82/EntryId/8/Creating-Android-button-with-image-and-text-using-relative-layout.aspx There's a mu...

Binary To String/Text In Python

Answer : It looks like you are trying to decode ASCII characters from a binary string representation (bit string) of each character. You can take each block of eight characters (a byte), convert that to an integer, and then convert that to a character with chr() : >>> X = "0110100001101001" >>> print(chr(int(X[:8], 2))) h >>> print(chr(int(X[8:], 2))) i Assuming that the values encoded in the string are ASCII this will give you the characters. You can generalise it like this: def decode_binary_string(s): return ''.join(chr(int(s[i*8:i*8+8],2)) for i in range(len(s)//8)) >>> decode_binary_string(X) hi If you want to keep it in the original encoding you don't need to decode any further. Usually you would convert the incoming string into a Python unicode string and that can be done like this (Python 2): def decode_binary_string(s, encoding='UTF-8'): byte_string = ''.join(chr(int(s[i*8:i*8+8]...