Android - 以编程方式操作ListView下方的按钮位置

rah*_*ame 2 java android listview android-layout

我目前想要遵循这种布局,但不知道如何控制下面的按钮.我的问题是,无论列表视图的宽度如何,图像都会伸展自己.我想按照下面的布局.我正在使用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;
}
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

The*_*uto 5

尝试实现这个:

          <?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" 
            android:listSelector="@drawable/list_selector">
    </ListView>


         <ImageButton
                    android:id="@+id/imageButton1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentBottom="true"
                    android:background="@null"
                    android:src="@drawable/navigation_back" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我相信它会对你有所帮助.谢谢