始终使图像按钮大小为正方形。 Android
|
我有一个图像按钮。如果需要,我可以将其替换为自定义视图。我需要将“图像按钮”的高度指定为Fill_parent。使图像延伸到屏幕上的可用高度。这样做时,我不想放宽宽度。我希望它是最小的高度,如果大于高度,那不是问题。我不想这么久了。
在执行此操作的同时,我还希望保持宽高比。请让我知道我需要调整以获得这些视图的参数。在这方面的任何帮助都将受到赞赏。感谢您的帮助和时间。
编辑:下面是完整的xml,在其中我尝试使用高度为fill_parent的水平滚动视图,并尝试使用适合其高度的图像填充图像,并根据纵横比扩大或缩小宽度。即使图像很小,我也要按比例放大,以使高度始终占据“水平”滚动视图。
<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:layout_width=\"fill_parent\" android:layout_height=\"fill_parent\"
android:orientation=\"vertical\">
<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:layout_width=\"fill_parent\" android:layout_height=\"fill_parent\"
android:orientation=\"vertical\" android:layout_weight=\"3\"
android:background=\"#666666\">
</LinearLayout>
<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:layout_width=\"fill_parent\" android:layout_height=\"fill_parent\"
android:orientation=\"vertical\" android:layout_weight=\"7\"
android:background=\"#888888\">
<HorizontalScrollView android:id=\"@+id/horizontalScrollView1\"
android:layout_width=\"fill_parent\" android:layout_height=\"fill_parent\">
<LinearLayout android:id=\"@+id/linearLayout1\"
android:layout_width=\"fill_parent\" android:layout_height=\"fill_parent\"
android:orientation=\"horizontal\">
<ImageView android:src=\"@drawable/image1\"
android:layout_weight=\"1\" android:layout_width=\"wrap_content\"
android:layout_height=\"fill_parent\" android:adjustViewBounds=\"true\"
android:id=\"@+id/attachimagebutton_2\" />
<ImageView android:src=\"@drawable/image2\"
android:layout_weight=\"1\" android:layout_width=\"wrap_content\"
android:layout_height=\"fill_parent\" android:adjustViewBounds=\"true\"
android:id=\"@+id/attachimagebutton_2\" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</LinearLayout>
没有找到相关结果
已邀请:
3 个回复
踩什不
... 您可以在XML中添加
,为其指定
,图像源,高度为
,宽度为
,并将宽高比固定为
。然后,您还可以添加
,并在您的
的代码中找到它。然后您可以添加ѭ9。 希望能奏效
场竟矩喘崩
,下一步是使用自定义视图扩展
类以将其大小设置为正方形,这非常简单。 因此,创建新类,将其命名为
,并扩展
。添加带有上下文和属性的默认构造函数,并让其调用super函数,您无需添加任何其他内容。 现在,覆盖
方法(该方法将以int值形式提供给您测量的宽度和高度),取最小值,然后(根据该方法的要求)使用新的最小值调用ѭ15so,使其成为正方形。它对我有用,如果您有点迷路,这里是代码:
喷乡顾沥沪
}