Android different EditText backgrounds for different states using shapes, selector or list

I suggest to use NinePatch images to customize your EditText. Here goes an example based on my code: The Selector: <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_window_focused=”false” android:state_enabled=”true” android:drawable=”@drawable/twitter_im_edittext_normal” /> <item android:state_window_focused=”false” android:state_enabled=”false” android:drawable=”@drawable/twitter_im_edittext_normal” /> <item android:state_pressed=”true” android:drawable=”@drawable/twitter_im_edittext_normal” /> <item android:state_enabled=”true” android:state_focused=”true” android:drawable=”@drawable/twitter_im_edittext_focused” /> <item android:state_enabled=”true” android:drawable=”@drawable/twitter_im_edittext_normal” /> <item android:state_focused=”true” android:drawable=”@drawable/twitter_im_edittext_focused” /> <item android:drawable=”@drawable/twitter_im_edittext_normal” /> </selector> Use selector … Read more

Java make a directed line and make it move

This is a basic example that demonstrates the use of a Path2D, to define a custom shape and an AffineTransformation to transform the shape. This example will cause the arrow to point towards the mouse as it moves over the panel import java.awt.BasicStroke; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.Graphics2D; … Read more

How to create a DataFrame of random integers with Pandas?

numpy.random.randint accepts a third argument (size) , in which you can specify the size of the output array. You can use this to create your DataFrame – df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list(‘ABCD’)) Here – np.random.randint(0,100,size=(100, 4)) – creates an output array of size (100,4) with random integer elements between [0,100) . Demo – import numpy … Read more

How do I scale a PyGame image (Surface) with respect to its center?

You missed to update the size of self.pixeltitlerect after the Surface has been scaled: self.pixeltitle = pg.transform.scale(self.pixeltitle,(xsize,ysize)) # size of surface has been changed get the new rectangle self.pixeltitlerect = self.pixeltitle.get_rect() self.pixeltitlerect.center = (250,120) self.screen.blit(self.pixeltitle,self.pixeltitlerect) Or even shorter (see pygame.Surface.get_rect()): self.pixeltitle = pg.transform.scale(self.pixeltitle,(xsize,ysize)) self.pixeltitlerect = self.pixeltitle.get_rect(center = (250,120)) self.screen.blit(self.pixeltitle,self.pixeltitlerect) Do not scale the original Surface. … Read more

Two Rectangles intersection

if (X1+W1<X2 or X2+W2<X1 or Y1+H1<Y2 or Y2+H2<Y1): Intersection = Empty else: Intersection = Not Empty If you have four coordinates – ((X,Y),(A,B)) and ((X1,Y1),(A1,B1)) – rather than two plus width and height, it would look like this: if (A<X1 or A1<X or B<Y1 or B1<Y): Intersection = Empty else: Intersection = Not Empty

How to make gradient background in android

Visual examples help with this kind of question. Boilerplate In order to create a gradient, you create an xml file in res/drawable. I am calling mine my_gradient_drawable.xml: <?xml version=”1.0″ encoding=”utf-8″?> <shape xmlns:android=”http://schemas.android.com/apk/res/android”> <gradient android:type=”linear” android:angle=”0″ android:startColor=”#f6ee19″ android:endColor=”#115ede” /> </shape> You set it to the background of some view. For example: <View android:layout_width=”200dp” android:layout_height=”100dp” android:background=”@drawable/my_gradient_drawable”/> type=”linear” … Read more