Tag: layout

Android center view in FrameLayout doesn't work

I have a FrameLayout in which I have 2 controls: – a custom view which draws a image and some text on it – a textview with a text I want to center both in the FrameLayout but I can’t manage to do it. The Texview is centered just fine, my cusom view remains on […]

Adding view to bottom of layout inside a scrollview

So my layout looks basically like this: <ScrollView> <RelativeLayout> <BunchOfViews/> <ImageView android:layout_alignParentBottom=”true”/> </RelativeLayout> </ScrollView> I have the ScrollView so all of the layout always is visible no matter the height of the screen. The problem is that on a very high screen, I still want my ImageView to be at the bottom. However, a child […]

NullPointerException that doesn't point to any line in my code

I am working on a game where the player can drag and drop things around the screen. I’ve got a private method which allows me to simulate a drag/drop event for any of the items that the player can move around. For the dragging I am actually leaving the view that they touched where it […]

Center two buttons horizontally

I try to arrange two buttons (with images on them which work fine) next to each other and to center them horizontally. That’s what I have so far: <LinearLayout android:orientation=”horizontal” android:layout_below=”@id/radioGroup” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_gravity=”center_horizontal|center”> <Button android:id=”@+id/allow” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_below=”@id/radioGroup” android:layout_gravity=”center_horizontal” android:drawableLeft=”@drawable/accept_btn” android:text=”Allow”/> <Button android:id=”@+id/deny” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_toRightOf=”@id/allow” android:layout_below=”@id/radioGroup” android:layout_gravity=”center_horizontal” android:drawableLeft=”@drawable/block_btn” android:text=”Deny”/> </LinearLayout> Unfortunately they are […]

What is the correct way to specify dimensions in DIP from Java code?

I found that it is possible to set dimensions of my interface elements in XML layouts using DIPs as in following fragment: android:layout_width=”10dip” But all Java interface takes integer as arguments and there is no way to specify dimensions in DIPs. What is the correct way to calculate this? I figured that I have to […]

Android — How to position View off-screen?

I’m trying to animate a simple ImageView in my application and I want it to slide in from the bottom of the screen and come to a resting position where the top 50px of the view is off the top of the screen (e.g. the final position of the ImageView should be -50px in X). […]

How to set property “android:drawableTop” of a button at runtime

How to set property “android:drawableTop” of a button at runtime

Why does my android activity always start scrolled to the bottom?

Whenever I start this activity, it always starts bottomed out–scrolled all the way to the bottom. I am not doing anything weird in the activity OnCreate (or anywhere for that matter) that I would expect to change the scroll position. I have tried setting focus to the topmost focusable control, and the scrollto method, but […]

How do I prevent an EditText from resizing itself when the user is typing?

I have an EditText and a Button set next to each other on the same horizontal line. It looks great, except when the user enters a lot of text, the EditText is resized, and the Button is squished. I have both EditText and Button set to layout_width=”wrap_content”. “fill_parent” messes up the layout, and I don’t […]

How to get a button's height to match another element's height?

I want to put a button next to a EditText and I want their heights to match. For example, from the built in Android browser: The Go button is the same height as the EditText field. I know I could wrap both these views in a parent layout view, and set both of their heights […]

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.