【问题标题】:how to put bottom menu in android app如何在android应用程序中放置底部菜单
【发布时间】:2013-10-17 04:01:54
【问题描述】:

我想在 android 应用程序中创建一个底部菜单,如下所示:

我写了下面的代码,但它返回了一些错误

        <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>

我把这张图片分成五个按钮,其中一个是圆形的,两个是方形的,两个是..

这是它的显示方式:

我该如何解决这个问题

【问题讨论】:

  • “但它返回给我一些错误”是什么意思?它有什么问题?您是否有描述错误行为的屏幕截图?

标签: android menu styles geometry


【解决方案1】:

LinearLayout 将简单地按顺序显示其每个子视图。它不支持分层、重叠或堆叠视图。

我建议切换到RelativeLayout,它确实支持重叠视图。

另一种选择是简单地将您定义每个按钮背景边界的位置调整为类似这样,这将在 LinearLayout 中起作用:

【讨论】:

    【解决方案2】:

    使用相对布局并将其与底部对齐。在这里面有一个按钮和一个分隔符的单独相对布局。下一个相对布局放置在第一个右侧,带有另一个按钮和分隔线。这样做。

      <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>
    

    【讨论】:

    • 我用过它,它可以工作,但我必须将此菜单调整为所有屏幕、大小,因为如果我更改模拟器,菜单不会调整
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多