0

Android 用の Hotmail アプリについて考えてみましょう。メールをチェックすると、下部に「既読にする」「未読にする」「削除する」という3つのボタンが表示されます。 チェックを外すと、ボタンが消えます。

これのレイアウトは何ですか?私はこれを試しましたが、下部にスクロールの問題が発生します (最後の項目が表示されません):

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@android:color/darker_gray"
    android:orientation="horizontal"
    android:paddingLeft="5dip"
    android:paddingRight="5dip"
    android:paddingTop="5dip" >

    <Button
        android:id="@+id/bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:enabled="false"
        android:text="@string/mark_read" />
</LinearLayout>

次に、このようなものも表示/非表示にする必要がありますか?

4

1 に答える 1

2

下部のlinearlayoutの表示を変更すると、表示/非表示になります。IDを付けてから

LinearLayout bottomLayout = (LinearLayout)findViewById(R.id.someId);
bottomLayout.setVisibility(View.GONE)// or View.VISIBLE

スクロールの問題については、RelativeLayoutがビューコンポーネントをオーバーレイするために発生します。そのため、ListViewの下部にオーバーレイするボタンを表示/非表示にするか、RelativelayoutをLinearLayoutに変更して、ListViewがボタンの前で終了して表示を変更することができます。

突然ボタンを表示し、ListView自体のサイズを変更する必要がある場合に、これが非常に見栄えがするかどうかはわかりませんが。

視認性に関する注意

setVisibility(View.GONE);

レイアウトからビューが削除され、これにより他のコンポーネントのサイズが変更される場合があります。ただし、

setVisibility(View.INVISIBLE);

ビューがレイアウトで占めていたスペースを維持し、ビューを非表示にするだけで、サイズ変更は発生しません。

于 2011-12-14T22:30:17.703 に答える