【发布时间】:2012-12-16 18:54:43
【问题描述】:
我想在我的程序顶部设置两个按钮,将用户带到不同的活动。我在格式化时遇到了很多问题。
如何使按钮根据屏幕尺寸按比例拉伸?现在,对于一种屏幕尺寸,它们看起来还不错,然后我将切换到另一种屏幕尺寸,它会显得全部被弄脏或拉伸。我已经尝试了所有不同的 ScaleTypes,但似乎都没有什么不同。我也去了,并使用Shubhayu's answer按比例将所有图像保存到正确的尺寸,如 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 size resolution imagebutton