Android 我应该使用哪种布局?
我很困惑。我想显示地图,在地图下方显示5个按钮。我使用RelativeLayout,但程序只显示产品按钮。为什么?我不知道我使用哪种布局(线性、相对、帧或绝对)!!请帮帮我。我怎样才能更正这个代码 location.xml:Android 我应该使用哪种布局?,android,layout,Android,Layout,我很困惑。我想显示地图,在地图下方显示5个按钮。我使用RelativeLayout,但程序只显示产品按钮。为什么?我不知道我使用哪种布局(线性、相对、帧或绝对)!!请帮帮我。我怎样才能更正这个代码 location.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frame"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:apiKey="0cPRv243zM1_S3ydsNg8MJP9_6BfCp642jOhPvQ"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:layout_gravity="bottom"
android:orientation="horizontal" >
<Button
android:id="@+id/button_home"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/home_icon"
android:text="@string/button_home"
android:textColor="@color/text_home" />
<Button
android:id="@+id/button_product"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/product_icon"
android:onClick="Product"
android:text="@string/button_product"
android:textColor="@color/text_product" />
</LinearLayout>
</LinearLayout>
- 线性布局:当我们需要安排 以水平或垂直方式显示小部件/视图。 排列方向可以设置为水平或垂直, 默认情况下,它是水平的
- TableLayout:如果需要排列布局的小部件/视图 以行和列的形式,我们使用这个布局对象。 这类似于html表。单元格可以跨列。 TableLayout不显示其边框。我们可以被强迫 通过设置列的各自属性来收缩和拉伸, “TableRow”是另一个应该结合使用的助手小部件 用桌面布局
- RelativeLayout:此处显示每个小部件/视图的位置 彼此相对/依赖。例如,当需要布局时 这样,它在编辑文本框的左侧有一个文本视图和一个按钮 就在编辑文本下面。各视图之间的关系在设计中得到了注意 一次迭代,因此如果视图B的位置取决于视图A的位置, 视图A必须位于布局的第一位
- 框架布局:这是一种非常简单的布局,用于保存节 屏幕空白的一部分,用于在运行时显示一个项目或一组项目。所有的 在framelayout中添加的元素将添加到屏幕的左上角
- 绝对布局:需要指定精确的x和y坐标时 视图的位置,然后需要使用绝对布局。这个布局是 难以维护
android:layout_toLeftOf="@+id/button_product"
这是错误的@+id
创建一个id,在这种情况下使用@id
我建议在这种情况下进行线性布局。将这些按钮放入其中,并用一些边距调整它们以回答您的特定问题:不要说主页按钮在产品按钮的左侧,而应该说产品按钮在主页按钮的右侧。当RelativeLayout膨胀时,布局以线性方式解析,因此如果视图a相对于视图B定位,则视图B必须位于第一位
<Button
android:id="@+id/button_home"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/home_icon"
android:text="@string/button_home"
android:textColor="@color/text_home"/>
<Button
android:id="@+id/button_product"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/button_home"
android:drawableTop="@drawable/product_icon"
android:onClick="Product"
android:text="@string/button_product"
android:textColor="@color/text_product" />
您可以使用“重力”和“对齐”来定位“主页”按钮,然后让其他四个按钮跟随它,每个按钮都位于它前面的按钮的右侧
祝你好运根据我的经验,我建议你使用线性布局。你必须在地图下方添加5个按钮。还是它的动力?谢谢。我想,我的程序使用LinearLayout或RelativeLayout。这是真的吗??但当我使用LinearLayout时,程序只显示map,不显示Buton。为什么?或者当我使用RelativeLayout时,程序只显示Product按钮,不显示home按钮。为什么?我编辑第一篇文章,然后用LinearLayout@PariyaDaghoghi:尝试,将
android:layout\u height=“fill\u parent”
更改为android:layout\u height=“wrap\u content”
在您的中是否喜欢这种方式b1 b2 b3 b4 b5。?在彼此旁边和上方查看地图?@chintankhetiya:您向谁提问?@chintankhetiya:然后在您的评论中提到名称为@Pariya Daghoghi
。。。这将有助于确定向您提问的人。
android:layout_toRightOf="@id/button_home"