Androidで横メニューを作りたいです。Androidは縦に展開する展開可能なリストビューをサポートしていますが、メニューを横に展開したいです。画像を参照してください
説明:
画像では、Menu1、menu2、menu3 がメイン メニューで、s1、s2、s3 がメニュー 1 のサブ項目です。メイン メニューをクリックした場合、そのサブ項目は展開する必要があります。
Androidで横メニューを作りたいです。Androidは縦に展開する展開可能なリストビューをサポートしていますが、メニューを横に展開したいです。画像を参照してください
説明:
画像では、Menu1、menu2、menu3 がメイン メニューで、s1、s2、s3 がメニュー 1 のサブ項目です。メイン メニューをクリックした場合、そのサブ項目は展開する必要があります。
サブメニューを LinearLayout に配置し、onClickListener の View.VISIBLE/View.GONE で再生を追加できます。
簡単な例です。自分で完了する必要があります。
xmlで。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/attachments_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<Button
android:id="@+id/btn_menu1"
android:layout_width="0dp"
android:layout_height="50dp"
android:text="Menu1"
android:layout_weight="1"
/>
<LinearLayout
android:id="@+id/subview_menu1"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="2"
android:visibility="gone"
>
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:text="S1"
android:layout_weight="1"
/>
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:text="S2"
android:layout_weight="1"
/>
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:text="S3"
android:layout_weight="1"
/>
</LinearLayout>
<Button
android:layout_width="0dp"
android:layout_height="50dp"
android:text="Menu2"
android:layout_weight="1"
/>
<Button
android:layout_width="0dp"
android:layout_height="50dp"
android:text="Menu3"
android:layout_weight="1"
/>
</LinearLayout>
btn_menu1 の OnClickListener
public void onClick(View v) {
if (subview_menu1.isShown()) {
subview_menu1.setVisibility(View.GONE);
}
else{
subview_menu1.setVisibility(View.VISIBLE);
}
}