android - 使用 4 个可调整大小的按钮制作布局

标签 android android-layout

我一直在寻找进行这种布局的最佳方式:

enter image description here

底部的四个按钮应尽可能占用更多空间,但每个按钮的大小必须与其他按钮相同。 我尝试将 TableLayout 和一些 LinearLayout 嫁接在一起,但我得不到我想要的结果。

最佳答案

代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical" >
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Button" />

        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Button" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button3"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Button" />

        <Button
            android:id="@+id/button4"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Button" />
    </LinearLayout>
</LinearLayout>

enter image description here

关于android - 使用 4 个可调整大小的按钮制作布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15002587/

相关文章:

java - 如何显示其他用户的通知?

java.lang.NullPointerException 在 android.support.v7.widget.RecyclerView.onMeasure ,交错网格布局

java - 当我将监听器传递给异步任务时出现类转换错误

android - 如何在 SQLite 中查询等于今天的日期?

android - 如何在同一 View 上实现触摸监听器和捏合缩放?

android - 没有viewpager的自定义Tablayout隐藏了textview

android - 是否可以使用可扩展 ListView 进行小计?

java - 如何在 Android 上以编程方式使用 View

Android LayerDrawable.setDrawableByLayerId 不适用于 HTC Sensation(和其他?)

android - 目标是否存在于 android 中,因为它存在于 iOS 中?