根据屏幕android调整按钮大小时保持宽高比

时间:2019-02-25 19:11:23

标签: android xml android-linearlayout android-button

如果我们要在“线性”布局或“表格”布局行中放置一些相同尺寸的按钮,并在每个屏幕尺寸中保持所有按钮的长宽比,那该怎么办?

要声明它,我们有一些图片:

enter image description here enter image description here

这些图像不是我所需要的,接下来我想展示我的愿望方案:

enter image description here enter image description here

请给我您对以下XML的想法,以设计活动

<TableRow
            android:background="#64c7c7c7"
            android:orientation="horizontal"
            android:padding="10dp"
            android:gravity="center"
            android:weightSum="4">
                <android.support.v7.widget.AppCompatButton
                    android:id="@+id/btn_open"
                    android:layout_weight="1"
                    android:layout_height="wrap_content"
                    android:focusable="true"
                    android:background="@drawable/btn_open"/>
                <android.support.v7.widget.AppCompatButton
                    android:layout_weight="1"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="1dp"
                    android:layout_marginEnd="1dp"
                    android:focusable="true"
                    android:background="@drawable/btn_read"/>
                <android.support.v7.widget.AppCompatButton
                    android:id="@+id/btn_read"
                    android:layout_weight="1"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="1dp"
                    android:layout_marginEnd="1dp"
                    android:focusable="true"
                    android:background="@drawable/btn_read"/>
                <android.support.v7.widget.AppCompatButton
                    android:id="@+id/btn_close"
                    android:layout_weight="1"
                    android:layout_height="wrap_content"
                    android:focusable="true"
                    android:background="@drawable/btn_close"/>
        </TableRow>

0 个答案:

没有答案
相关问题