1

Listviewを使ったアプリを作っています

main_acivity.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"
    android:background="@drawable/common_bg_common"
    tools:context=".MainActivity" >
    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="#000000"
        android:dividerHeight="3sp" >
    </ListView>

</RelativeLayout>

そしてcostomItemは以下です

costomo_cell.xml

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF" >

    <LinearLayout
        android:id="@+id/linear1"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:layout_alignParentTop="true"
        android:background="#cc9933"
        android:orientation="vertical" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_vertical|center_horizontal"
            android:text="dummyCanvas"
            android:textColor="#000000" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linear2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/linear1"
        android:background="#cc3333"
        android:orientation="vertical" >

        <TextView 
            android:id="@+id/_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#000000"/>
    </LinearLayout>

</RelativeLayout>

今、私は1つのアイテムで画面を埋めたいと思っています。custom_cell.xml に match_parent を記述しようと考えていますが、できません。

私はxxdpを書きたくありません。Linear1 は画面サイズの 2/3 サイズです。その他のコンテンツ(linear2)は1/3サイズ...

カスタム セル レイアウトを構成するにはどうすればよいですか?

--------編集済み---- スクリーンショットをアップロードします。黒い線は 1 つの項目別です。画面サイズを調整したい 捕獲

4

2 に答える 2

3
class MyListItemView extends LinearLayout {

public MyListItemView(Context context) {
    super(context);
    inflate(getContext(), R.layout.costomo_cell, this);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int height = getResources().getDisplayMetrics().heightPixels;
    super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
}

アダプタの getView で MyListItemView インスタンスをインスタンス化します

于 2013-03-04T08:17:53.530 に答える