【问题标题】:How to make square buttons depending on screen size如何根据屏幕尺寸制作方形按钮
【发布时间】:2018-06-30 10:21:46
【问题描述】:

我需要可滚动的布局,单行上有 2 个方形按钮。 (2 x N 表) 宽度应取决于屏幕尺寸。 (屏幕宽度/2) 高度应该等于宽度。 (因为它是方形按钮)

【问题讨论】:

  • 您是否尝试过使用网格或表格布局?
  • 是的。但它不起作用。可能是我的背景图片中的问题。它的分辨率为 1000x1000。
  • 好的,你是怎么加载的?尝试使用 Glide 或 Picasso 缩放它。您还应该在问题开始时澄清...

标签: java android xml android-layout


【解决方案1】:

我找到了解决方案!它适用于高分辨率方形图像。也可以滚动。

<?xml version="1.0" encoding="utf-8"?>
        <ScrollView android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:scrollbars="none"
            android:layout_weight="1"
            xmlns:android="http://schemas.android.com/apk/res/android">
            <TableLayout
                android:id="@+id/tableLayout1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:padding="0dp"
                android:isScrollContainer="true">

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:weightSum="2">

                <ImageButton
                    android:background="@null"
                    android:id="@+id/imageButcton2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:cropToPadding="false"
                    android:scaleType="centerInside"
                    app:srcCompat="@drawable/coffee0" />

                <ImageButton
                    android:background="@null"
                    android:id="@+id/imageButzxton"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:scaleType="centerInside"
                    app:srcCompat="@drawable/coffee0" />

            </TableRow>


            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:weightSum="2">

                <ImageButton
                    android:background="@null"
                    android:id="@+id/sdas"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:scaleType="centerInside"
                    app:srcCompat="@drawable/coffee0" />

                <ImageButton
                    android:background="@null"
                    android:id="@+id/imageButsadasdastdon"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:scaleType="centerInside"
                    app:srcCompat="@drawable/coffee0" />

            </TableRow>
                <TableRow
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:weightSum="2">

                    <ImageButton
                        android:background="@null"
                        android:id="@+id/imageBzxzzczxzutton2"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:adjustViewBounds="true"
                        android:scaleType="centerInside"
                        app:srcCompat="@drawable/coffee0" />

                    <ImageButton
                        android:background="@null"
                        android:id="@+id/imageButtxzczxdon"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:adjustViewBounds="true"
                        android:scaleType="centerInside"
                        app:srcCompat="@drawable/coffee0" />

                </TableRow>    <TableRow
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:weightSum="2">

                <ImageButton
                    android:background="@null"
                    android:id="@+id/imagexzzczButton2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:scaleType="centerInside"
                    app:srcCompat="@drawable/coffee0" />

                <ImageButton
                    android:background="@null"
                    android:id="@+id/imageButtdon"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:scaleType="centerInside"
                    app:srcCompat="@drawable/coffee0" />

            </TableRow>
                <TableRow
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:weightSum="2">

                    <ImageButton
                        android:background="@null"
                        android:id="@+id/imaxzzczgeButton2"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:adjustViewBounds="true"
                        android:scaleType="centerInside"
                        app:srcCompat="@drawable/coffee0" />

                    <ImageButton
                        android:background="@null"
                        android:id="@+id/imagezxzcButtdon"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:adjustViewBounds="true"
                        android:scaleType="centerInside"
                        app:srcCompat="@drawable/coffee0" />

                </TableRow>


        </TableLayout>
        </ScrollView>

【讨论】:

    【解决方案2】:

    我想,你想要这样的东西:

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/dll"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
    
        >
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
           android:layout_columnWeight="1"
            ></Button>
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
           android:layout_columnWeight="1"></Button>
    </GridLayout>
    </ScrollView>
    

    【讨论】:

      猜你喜欢
      • 2019-03-23
      • 1970-01-01
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-17
      相关资源
      最近更新 更多