Flexible relativelayout with list and image button
I want to create a following kind of layout in android , rite now i have created with fixed height of listview which is causing a problem with different dimension of screens of mobiles.
Initially when this screen appears a button will be at the bottom side only with empty listview and as an when the items will get added in a list view , it grows but button will remain steady at the bottom.
so far i have written following code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/cText"
android:src="@drawable/c_text"
android:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dip"
/>
<ListView
android:id="@android:id/list"开发者_StackOverflow中文版
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
/>
<ImageButton
android:id="@+id/cBtn"
android:layout_width="150dip"
android:layout_height="52dip"
android:src="@drawable/preview"
android:layout_alignParentTop="@+id/list"
android:layout_gravity="center_horizontal"/>
</RelativeLayout>
Try this
< ?xml version="1.0" encoding="utf-8"?>
< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageButton
android:id="@+id/cBtn"
android:layout_centerHorizontal="true"
android:layout_width="150dip"
android:layout_height="52dip"
android:src="@drawable/preview"
android:layout_alignParentBottom="true"
/>
<ListView
android:id="@+id//listview01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/cBtn"
android:layout_marginBottom="10dip"
/>
< /RelativeLayout>
You can add a Button as a footer to List View. The sample code sinppet is shown below
Step1: Create a Button
<Button android:id="@+id/footer" android:gravity="center"
android:layout_gravity="center"
android:text="My Footer"
android:layout_width="wrap_content"
android:layout_height="0dp" android:layout_weight="1"/>
Step2: Make it as Footer to the List View
ListView myList;
View footerView;
ViewGroup footerViewOriginal = (ViewGroup) findViewById(R.id.footer);
footerView = inflater2.inflate(R.layout.footer,footerViewOriginal);
footerView.findViewById(R.id.footer);
myList.addFooterView(footerView, null, true);
Step3: Create on ClickListener and write the action what you want to perform
footerView.findViewById(R.id.footer).setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
精彩评论