1

画面全体を埋めたいリストビューがありますが、リストビューには4つの項目があります。4 つの項目が入力されると、下に空白が残ります。スクリーンショットで確認できます。空白を残します。画面全体をカバーしたい。

ここに画像の説明を入力

私はこのようにしたい:

ここに画像の説明を入力

ここにソースコードがあります

MainActivity.java.

public class MainActivity extends Activity {
    ListView resultPane;
    List<Taskinfo> list;
    CustomAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        resultPane = (ListView) findViewById(R.id.mylist);
        list = new ArrayList<Taskinfo>();
        Resources res = getResources(); // resource handle
        Drawable drawable = res.getDrawable(R.drawable.browse_home);

        list.add(new Taskinfo("Browse", drawable));
        drawable = res.getDrawable(R.drawable.jewelry);
        list.add(new Taskinfo("Whats New", drawable));
        drawable = res.getDrawable(R.drawable.show);
        list.add(new Taskinfo("Upcoming Show", drawable));
        drawable = res.getDrawable(R.drawable.contact);
        list.add(new Taskinfo("Contact Us", drawable));

        adapter = new CustomAdapter(this, list);
        resultPane.setAdapter(adapter);



    }

}

CustomAdapter.java

public class CustomAdapter extends BaseAdapter {
    private Context context;
    private List<Taskinfo> list;

    public CustomAdapter(Context context, List<Taskinfo> list) {
        this.context = context;
        this.list = list;

    }

    public View getView(int index, View view, final ViewGroup parent) {

        if (view == null) {
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            view = inflater.inflate(R.layout.single_list_item, parent, false);
        }

        Taskinfo t = list.get(index);

        RelativeLayout l = (RelativeLayout) view
                .findViewById(R.id.testrelative);

        l.setBackgroundDrawable(t.getImage());

        TextView textView = (TextView) view.findViewById(R.id.title);
        textView.setText(t.getName());

        return view;
    }

}

single_list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/testrelative"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/browse_home"
    android:orientation="horizontal"
    android:padding="5dip" >

    <!-- ListRow Left sied Thumbnail image -->

    <LinearLayout
        android:id="@+id/thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginRight="5dip"

        android:padding="3dip" >
    </LinearLayout>

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="16dp"
        android:text=""
        android:textColor="#040404"
        android:textSize="15dip"
        android:textStyle="bold"
        android:typeface="sans" />

</RelativeLayout>

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="45sp"
        android:id="@+id/llayout"
        android:background="@drawable/navbar"
        android:padding="3sp" >



        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="Golden Stone"

            android:textColor="@color/white"
            android:textSize="20sp" >
        </TextView>


    </LinearLayout>


   <ListView
        android:id="@+id/mylist"
        android:layout_width="match_parent"
        android:layout_below="@id/llayout"
        android:layout_height="match_parent" >
    </ListView>

</RelativeLayout>
4

3 に答える 3

2

そういう場合に使うListViewのは奇妙で不要です。制約について考えて (アイテムがオーバーフローしたらどうなるかなど)、適切なレイアウト マネージャーを使用してください。LinearLayoutゼロ以外のレイアウト ウェイトを持つ最後の項目を持つ垂直のように。

ListViewオンザフライでリスト項目を生成する抽象化が必要な場合にのみ意味があります。

于 2013-05-08T19:44:48.550 に答える