我有一个图像按钮。如果需要,我可以用自定义视图替换它。我需要将图像按钮的高度指定为Fill_parent。以便图像在屏幕上延伸到可用高度。当我这样做时,我不想宽松。我希望它是一个最小的高度,如果大于高度,那么它不是一个问题。我不想这么久。 虽然我这样做,我也想保持高宽比。请让我知道我需要调整的参数以获得这种观点。在这方面的任何形式的帮助表示赞赏。感谢您的帮助和时间。使图像按钮大小始终为正方形。 Android
编辑:下面是完整的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>
你尝试过什么,我写的吗?如果我理解你在说什么,那么代码应该这样做...我的意思是,adjustViewBounds和layout_width属性中的wrap_content将以缩放方式修复宽度 – CodeKrieger
但是,如果容器是容器,如何将图像伸展到300x300 300x72 ...在这种情况下,它会始终是72x72,因为它先填充最小的长度....为什么你把它作为300x72?你可以做得更大吗? 你不能有不同的高度和宽度,因为你有一个正方形,你保持高宽比,再想一想你指的是什么 – CodeKrieger
我的意思就像我看到的结果是300x72。这不是理想的结果。期望的结果是300x300。我的高度设置为“fill_parent”。这大约是300.宽度设置为wrap_content。我希望图像从72x72扩展到300x300。如果图像是600x800,我希望它设置为300x400,因为最大高度为300.但是我的要求中没有最大宽度。这可以做到吗? 也想提一下,高度约为300.它必须设置为fill_parent,而不是特定的dp,因为我需要为所有类型的屏幕尺寸设置。 – Vinodtiru