我有个问题:
我有一个包含一行和两个单元格的表格。我把桌子分成了屏幕的一半。每个单元格中都有一个按钮,具有自己的按钮样式(android:background)。每个按钮样式都包含一个图像。但问题是图像(按钮)被拉伸了。我不知道我必须改变什么才能使图像不再被拉伸。
这是表格布局:
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">
<Button
android:id="@+id/a"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/aa" />
</FrameLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">
<Button
android:id="@+id/b"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="1"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:background="@drawable/bb" />
</FrameLayout>
</TableRow>
</TableLayout>
这是按钮样式:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/aa1"
android:state_pressed="true" />
<item android:drawable="@drawable/aa2" />
</selector>
我必须改变什么才能使图像不被拉伸?图像的比例应该是可用的,它应该被分割在屏幕的一半。
感谢帮助。这是非常重要的。
试试这个布局:使用ImageButton
代替Button
并在android:src
属性中添加图像。
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">
<ImageButton
android:id="@+id/a"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:background="@android:color/transparent"
android:padding="15dp"
android:src="@mipmap/ic_launcher" />
</FrameLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">
<ImageButton
android:id="@+id/b"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="1"
android:layout_marginBottom="5dp"
android:background="@android:color/transparent"
android:padding="15dp"
android:src="@mipmap/ic_launcher" />
</FrameLayout>
</TableRow>
</TableLayout>
输出:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句