Android LinearLayout Gradient Background

Ok I have managed to solve this using a selector. See code below: main_header.xml: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”50dip” android:orientation=”horizontal” android:background=”@drawable/main_header_selector”> </LinearLayout> main_header_selector.xml: <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item> <shape> <gradient android:angle=”90″ android:startColor=”#FFFF0000″ android:endColor=”#FF00FF00″ android:type=”linear” /> </shape> </item> </selector> Hopefully this helps someone who has the same problem.

Put buttons at bottom of screen with LinearLayout?

You need to ensure four things: Your outside LinearLayout has layout_height=”match_parent” Your inside LinearLayout has layout_weight=”1″ and layout_height=”0dp” Your TextView has layout_weight=”0″ You’ve set the gravity properly on your inner LinearLayout: android:gravity=”center|bottom” Notice that fill_parent does not mean “take up all available space”. However, if you use layout_height=”0dp” with layout_weight=”1″, then a view will take … Read more

How do you make a LinearLayout scrollable?

Wrap the linear layout with a <ScrollView> See here for an example: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout android:layout_width=”fill_parent” android:layout_height=”fill_parent” xmlns:android=”http://schemas.android.com/apk/res/android”> <ScrollView android:layout_width=”fill_parent” android:layout_height=”wrap_content”> <LinearLayout android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:orientation=”vertical”> <!– Content here –> </LinearLayout> </ScrollView> </LinearLayout> Note: fill_parent is deprecated and renamed to match_parent in API Level 8 and higher.

Android: How to measure total height of ListView [duplicate]

Finally I’ve done it! This is the working code which measures ListView height and sets ListView in full size: public static void getTotalHeightofListView(ListView listView) { ListAdapter mAdapter = listView.getAdapter(); int totalHeight = 0; for (int i = 0; i < mAdapter.getCount(); i++) { View mView = mAdapter.getView(i, null, listView); mView.measure( MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); totalHeight … Read more

Setting a maximum width on a ViewGroup

One option which is what I did is to extend LinearLayout and override the onMeasure function. For example: public class BoundedLinearLayout extends LinearLayout { private final int mBoundedWidth; private final int mBoundedHeight; public BoundedLinearLayout(Context context) { super(context); mBoundedWidth = 0; mBoundedHeight = 0; } public BoundedLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = … Read more

How to add border around linear layout except at the bottom?

Create an XML file named border.xml in the drawable folder and put the following code in it. <?xml version=”1.0″ encoding=”utf-8″?> <layer-list xmlns:android=”http://schemas.android.com/apk/res/android”> <item> <shape android:shape=”rectangle”> <solid android:color=”#FF0000″ /> </shape> </item> <item android:left=”5dp” android:right=”5dp” android:top=”5dp” > <shape android:shape=”rectangle”> <solid android:color=”#000000″ /> </shape> </item> </layer-list> Then add a background to your linear layout like this: android:background=”@drawable/border” EDIT … Read more

Scrolling with Multiple ListViews for Android

Forward touch event from touched view to other views. All your views will be synchronized expand/collapsed too. OnTouchListener mOnTouch = new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { MotionEvent newEvent = MotionEvent.obtain(event); switch(event.getAction()){ case MotionEvent.ACTION_MOVE: if(mTouched == null){ mTouched = v; } mMovingFlag = true; break; case MotionEvent.ACTION_UP: if(mMovingFlag==false){ newEvent.setAction(MotionEvent.ACTION_CANCEL); } mMovingFlag … Read more