Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ImageButton解析问题_Android_Layout_Size_Resolution_Imagebutton - Fatal编程技术网

Android ImageButton解析问题

Android ImageButton解析问题,android,layout,size,resolution,imagebutton,Android,Layout,Size,Resolution,Imagebutton,我想在我的程序顶部有两个按钮,让用户参加不同的活动。我在格式化方面遇到了很多麻烦 如何使按钮根据屏幕大小按比例拉伸?现在,对于一个屏幕大小,它们看起来很好,然后我将切换到另一个屏幕,它将显示为全部弄脏或拉伸。我尝试了所有不同的鳞片类型,但没有一个能起到作用。我还使用了xhdpi、hdpi等,按比例将所有图像保存到正确的大小 以下是我目前的代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

我想在我的程序顶部有两个按钮,让用户参加不同的活动。我在格式化方面遇到了很多麻烦

如何使按钮根据屏幕大小按比例拉伸?现在,对于一个屏幕大小,它们看起来很好,然后我将切换到另一个屏幕,它将显示为全部弄脏或拉伸。我尝试了所有不同的鳞片类型,但没有一个能起到作用。我还使用了xhdpi、hdpi等,按比例将所有图像保存到正确的大小

以下是我目前的代码:

<LinearLayout 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"
android:background="@drawable/brushed_metal_background_dark"
tools:context=".HomeActivity" >

<ImageButton
    android:id="@+id/incidentsSelect"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/incident_bar2"
    android:contentDescription="Incidents"
    android:onClick="chooseIncident"
    android:scaleType="center" />

<ImageButton
    android:id="@+id/operationalPeriodsSelect"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/operationalperiod_bar2"
    android:contentDescription="Operational Periods"
    android:onClick="chooseOperationalPeriod"
    android:scaleType="fitCenter" />


我猜您正在尝试均匀地调整屏幕顶部的按钮大小。如果是这种情况,那么您应该设置
android:layout\u width=“0dp”
android:background
更改为
android:src
,以保持纵横比。使用
android:scaleType=“centerInside”
将整个图像放入按钮区域,并可以选择使用
android:adjustViewBounds=true
删除空白。例如:

<ImageButton
    android:id="@+id/incidentsSelect"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:contentDescription="Incidents"
    android:onClick="chooseIncident"
    android:src="@drawable/incident_bar2"
    android:scaleType="centerInside"
    android:adjustViewBounds="true"/>

<ImageButton
    android:id="@+id/operationalPeriodsSelect"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:contentDescription="Operational Periods"
    android:onClick="chooseOperationalPeriod"
    android:src="@drawable/operationalperiod_bar2"
    android:scaleType="centerInside"
    android:adjustViewBounds="true"/>


只需使用android:layout\u width=“wrap\u content”

我不想让它们变得均匀,基本上是高度给了我问题。我认为它可以均匀地拉伸宽度,但不会拉伸高度,所以基本上如果屏幕稍微小一点,我的按钮又大又胖,如果它更大,它们会变得很瘦。谢谢!我还必须使用android:background=“@null”来摆脱讨厌的背景边框。