Tag: layout

How to retrieve the dimensions of a view?

I have a view made up of tablelayout, tablerows and textviews. I want it to look like a grid. I need to get the height and width of this grid. The methods getheight() and getwidth() always return 0. This happens when I format the grid dynamically and also when I use an xml version. How […]

Set margins in a LinearLayout programmatically

I’m trying to use Java (not XML) to create a LinearLayout with buttons that fill the screen, and have margins. Here is code that works without margins: LinearLayout buttonsView = new LinearLayout(this); buttonsView.setOrientation(LinearLayout.VERTICAL); for (int r = 0; r < 6; ++r) { Button btn = new Button(this); btn.setText(“A”); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); […]

Set the layout weight of a TextView programmatically

I’m trying to dynamically create TableRow objects and add them to a TableLayout. The TableRow objects has 2 items, a TextView and a CheckBox. The TextView items need to have their layout weight set to 1 to push the CheckBox items to the far right. I can’t find documentation on how to programmatically set the […]

Get screen dimensions in pixels

I created some custom elements, and I want to programmatically place them to the upper right corner (n pixels from the top edge and m pixels from the right edge). Therefore I need to get the screen width and screen height and then set position: int px = screenWidth – m; int py = screenHeight […]

In Android, how do I set margins in dp programmatically?

In this, this and this thread I tried to find an answer on how to set the margins on a single view. However, I was wondering if there isn’t an easier way. I’ll explain why I rather wouldn’t want to use this approach: I have a custom Button which extends Button. If the background is […]

How to make android app's background image repeat

I have set a background image in my app, but the background image is small and I want it to be repeated and fill in the whole screen. What should I do? <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:background=”@drawable/bg” android:tileMode=”repeat”>

Android Drawing Separator/Divider Line in Layout?

I would like to draw a line right in the middle of a layout and use it as a separator of other items like TextView. Is there a good widget for this. I don’t really want to use an image as it would be hard to match the other components to it. And I want […]

How to disable an Android button?

I have created a layout that contains two buttons, Next and Previous. In between the buttons I’m generating some dynamic views. So when I first launch the application I want to disable the “Previous” button since there wont be any previous views. I also want to disable the “Next” button when there are not more […]

What's the difference between fill_parent and wrap_content?

In Android, when layout out widgets, what’s the difference between fill_parent (match_parent in API Level 8 and higher) and wrap_content? Is there any documentation where you can point to? I’m interested in understanding it very well.

How to make layout with rounded corners..?

How can I make a layout with rounded corners? I want to apply rounded corners to my LinearLayout.

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