我目前想遵循这个布局,但不确定如何控制下面的按钮。我的问题是无论列表视图的宽度是多少,图像都会自行拉伸。我想按照下面的布局。我正在使用 Android 的后退按钮。
我对以编程方式控制图像的位置及其默认大小不太熟悉。按钮在里面addFooterView(btnLoadMore);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.load_main_groups_activty, container, false);
// Getting listview from xml
ListView lv = (ListView) rootView.findViewById(android.R.id.list);
// Creating a button - Load More
Button btnLoadMore = new Button(mContext);
btnLoadMore.setBackgroundResource(R.drawable.navigation_back);
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params2.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
btnLoadMore.setLayoutParams(params2);
// Adding button to listview at footer
lv.addFooterView(btnLoadMore);
return rootView;
}
load_main_groups_activty
<?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"
android:orientation="vertical"
android:background="@color/white"
>
<!-- Main ListView
Always give id value as list(@android:id/list)
-->
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
>
</ListView>
<FrameLayout
android:id="@+id/contentFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</RelativeLayout>