【发布时间】:2015-03-02 01:55:18
【问题描述】:
我使用以下内容在布局中显示按钮
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.2"
android:gravity="bottom|right"
android:orientation="vertical" >
<TableRow
android:id="@+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<Button
android:id="@+id/clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dip"
android:background="@drawable/butt2"
android:onClick="clk_clear"
android:scaleType="centerInside"
android:textColor="#000000"
android:textSize="50dp" />
</TableRow>
</LinearLayout>
这会将布局设置为可用高度的 20%,并在其中放置一个按钮
问题是当屏幕的 20% 小于图标的高度时,垂直挤压它但不保持纵横比,所以一个圆最终看起来像一个椭圆
更新
我尝试了以下方法,但它崩溃了,说它无法转换为
android.widget.TableRow$LayouParams
任何想法
Button txt1 = (Button) findViewById(R.id.clear);
int btnSize=txt1.getLayoutParams().width;
txt1.setLayoutParams(new LayoutParams(btnSize, btnSize));
也试过了
Button txt1 = (Button) findViewById(R.id.clear);
int btnSize=txt1.getHeight();
txt1.setWidth(btnSize);
看起来还是一个椭圆形
已解决,但图标非常小需要与线条大小相同 标记
【问题讨论】:
-
根据文档,要创建不同密度的图标,您应该遵循五个主要密度(中、高、x-高、 xx-high 和 xxx-high 分别)。你在关注这个吗?尝试按照上述方法使用不同大小的图标
-
你的意思是我必须把 png 缩小到每个文件夹中的相关大小吗?我的 png 在名为 res/drawable 的文件夹中,而不是在相应的文件夹中
-
是的,例如在 xhdpi 文件夹中放置 96x96,在 hdpi 文件夹中放置 72x72 图像,同名。
-
您在哪个设备上进行测试,或者您使用哪个模拟器 dpi?
-
nexus 10 模拟器和 Galaxy Note 10。平板电脑都有四屏,但试图让图标在所有屏幕上的比例相同
标签: android button scale aspect-ratio