如何在android应用程序中设置底部菜单
我想在android应用程序中创建一个底部菜单,如下所示: 我写了下面的代码,但它返回了一些错误如何在android应用程序中设置底部菜单,android,menu,styles,geometry,Android,Menu,Styles,Geometry,我想在android应用程序中创建一个底部菜单,如下所示: 我写了下面的代码,但它返回了一些错误 <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:id="@+id/bar_bas"
>
<Button
android:id="@+id/btn_circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#bfd2b0"
android:background="@drawable/right_left"
android:text="test" />
<Button
android:id="@+id/btn_circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#bfd2b0"
android:background="@drawable/left_circle"
android:text="test" />
<Button
android:id="@+id/btn_circle"
android:layout_marginBottom="-6dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#bfd2b0"
android:background="@drawable/circle"
android:text="test" />
<Button
android:id="@+id/btn_circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#bfd2b0"
android:background="@drawable/right_circle"
android:text="test" />
<Button
android:id="@+id/btn_circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#bfd2b0"
android:background="@drawable/right_left"
android:text="test" />
</LinearLayout>
我把这幅画分成五个按钮,其中一个是圆形的,两个是正方形的,还有两个
以下是它的显示方式:
如何解决此问题A
LinearLayout
将按顺序显示其每个子视图。它不支持分层、重叠或堆叠视图
我建议切换到RelativeLayout
,它确实支持重叠视图
另一种选择是简单地将定义每个按钮背景边界的位置调整为类似这样的位置,这将在线性布局中起作用
:
使用相对布局并将其与底部对齐。在这里面有一个按钮和一个分隔符单独的相对布局。下一个相对布局放置在第一个的右侧,带有另一个按钮和分隔符。像这样做
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="85dip"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="true">
<ImageView
android:id="@+id/imageview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:background="@drawable/some_drawable"/>
<ImageView
android:id="@+id/divider1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:src="@drawable/menu_divider" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout2"
android:layout_width="85dip"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/relativeLayout1"
android:clickable="true" >
<ImageView
android:id="@+id/imageview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:background="@drawable/some_drawable"/>
<ImageView
android:id="@+id/divider2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:src="@drawable/menu_divider" />
</RelativeLayout>
什么是“但它返回了错误的东西”呢?怎么了?你有描述错误行为的屏幕截图吗?我用过它,它可以工作,但我必须调整这个菜单到所有屏幕的大小,因为如果我改变模拟器,菜单不会调整