0

英語のアルファベットのリストビューが必要で、このリストビューを固定して常に表示したいのですが、ユーザーがスクロールできないようにしたくないということです。常に表示され、すべてのモバイル デバイスのすべての画面サイズに収まるようにするにはどうすればよいですか? 私はこのように試しました:

リストビュー

<ListView
            android:divider="#000000"
            android:id="@+id/lv_profile_listview_with_search_alphabets"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_weight="0.1"
             >
        </ListView>

リスト項目

<TextView
        android:id="@+id/tv_list_item_alphabet_oneAlphabet"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/alphabet_selector"
        android:gravity="center_horizontal"
        android:textColor="#040404"
        android:textSize="10dip"
        android:typeface="sans" 
        />

しかし、私のデバイスでは、画面のボタンにまだ空白の領域があります。

私が推測する解決策の1つは、アダプターで各リスト項目の高さをプログラムで設定することです。

li.setHeight(ScreenHeight/26);

しかし、ScreenHeight を取得する方法も、これが良い方法であることもわかりません。

助けてください

4

2 に答える 2

2

アイテムの高さを設定するのは本当に悪い考えです。画面サイズに相対的な高さを持たせたい場合は、垂直方向の LinearLayout を使用し、アイテムの高さをゼロに設定して重みを追加する必要があります。スクロールを無効にするには、android:clickable="false" 属性を追加してみてください。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1" >

    <ListView
        android:divider="#000000"
        android:id="@+id/lv_profile_listview_with_search_alphabets"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.3"
        android:clickable="false"/>

</LinearLayout>

垂直レイアウトの重みの合計が 1 で、重みが 0.3 の場合、画面の高さの 1/3 より少し小さいことを意味します。LinearLayout では、重みと向きによって相対的な幅または高さを設定できます。例えば ​​ListView の幅を画面幅 0.5 にし、高さを match_parent に設定する場合はこのようになります。item が 0dp の場合、LinearLayout は現在水平および幅であることに注意してください

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="1" >

    <ListView
        android:divider="#000000"
        android:id="@+id/lv_profile_listview_with_search_alphabets"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:clickable="false"/>

</LinearLayout>

コードで画面サイズに基づいてアイテムの高さを設定するのは、むしろ悪い習慣です。カスタム アイテム レイアウトを作成し、dimen からアイテムの layout_height を設定し、異なる解像度用に異なる dimens を追加することができます

http://developer.android.com/guide/topics/resources/more-resources.html#Dimension

http://developer.android.com/guide/topics/resources/providing-resources.html

これらの記事が役立つかもしれません

http://developer.android.com/guide/practices/screens_support.html

http://developer.android.com/training/multiscreen/index.html

于 2013-02-06T09:43:36.927 に答える
1

画面の高さを取得するには、次のようにします。

  listView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

    public void onGlobalLayout() {
      item.setMinimumHeight(listView.getHeight() / 26);
    }
  });

スクロールを許可しない場合は、次を試してください:

listView.setScrollContainer(false)
于 2013-02-06T09:48:53.303 に答える