How to center the content inside a linear layout?

I’m trying to center an ImageView inside a LinearLayout horizontally and vertically, but I just can’t do it. The main reason why I’m not using a RelativeLayout for that is because I need the layout_weight (my Activity consists of four columns that should be equally divided, and also responsive to different screen widths, each column … Read more

How do I use a compound drawable instead of a LinearLayout that contains an ImageView and a TextView

Ran the new Lint tool against my code. It came up with a lot of good suggestions, but this one I cannot understand. This tag and its children can be replaced by one and a compound drawable Issue: Checks whether the current node can be replaced by a TextView using compound drawables. A LinearLayout which … Read more

Android LinearLayout Gradient Background

I am having trouble applying a gradient background to a LinearLayout. This should be relatively simple from what I have read but it just doesn’t seem to work. For reference sakes I am developing on 2.1-update1. header_bg.xml: <?xml version=”1.0″ encoding=”utf-8″?> <shape xmlns:android=”http://schemas.android.com/apk/res/android” android:shape=”rectangle”> <gradient android:angle=”90″ android:startColor=”#FFFF0000″ android:endColor=”#FF00FF00″ android:type=”linear”/> </shape> main_header.xml: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” … Read more

Linear Layout and weight in Android

I always read about this funny weight value in the Android documentations. Now I want to try it for the first time but it isn’t working at all. As I understand it from the documentations this layout: <LinearLayout android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:orientation=”horizontal”> <Button android:text=”Register” android:id=”@+id/register” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:padding=”10dip” weight=”1″ /> <Button android:text=”Not this time” android:id=”@+id/cancel” android:layout_width=”wrap_content” … Read more

Is it possible to evenly distribute buttons across the width of a LinearLayout

I have a LinearLayout (oriented horizontally) that contains 3 buttons. I want the 3 buttons to have a fixed width and be evenly distributed across the width of the LinearLayout. I can manage this by setting the gravity of the LinearLayout to center and then adjusting the padding of the buttons, but this works for … Read more

frequent issues arising in android view, Error parsing XML: unbound prefix

I have frequent problem in android view, Error parsing XML: unbound prefix on Line 2. <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout android:orientation=”vertical” android:id=”@+id/myScrollLayout” android:layout_width=”fill_parent” android:layout_height=”wrap_content”> <TextView android:layout_height=”wrap_content” android:layout_width=”fill_parent” android:text=”Family” android:id=”@+id/Family” android:textSize=”16px” android:padding=”5px” android:textStyle=”bold” android:gravity=”center_horizontal”> </TextView> <ScrollView xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:orientation=”vertical” android:scrollbars=”vertical”> <LinearLayout android:orientation=”vertical” android:id=”@+id/myMainLayout” android:layout_width=”fill_parent” android:layout_height=”wrap_content”> </LinearLayout> </ScrollView> </LinearLayout> 16 Answers 16