我想在我的程序顶部有两个按钮,让用户可以进行不同的活动。我在格式化方面遇到了很多麻烦。Android ImageButton解决问题
我怎样才能让它按照屏幕大小按比例拉伸?现在,他们会看起来像一个屏幕大小,然后我会切换到一个不同的,它会出现所有的冲动或拉伸。我已经尝试了所有不同的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:background =“@ null”来摆脱恶意背景边界的事情。 –