Android 如何正确调整图片的大小?
嘿 视图上有两张图片,按钮上有一个按钮 XML:Android 如何正确调整图片的大小?,android,Android,嘿 视图上有两张图片,按钮上有一个按钮 XML: 我的问题:如何缩小显示版面所有元素的图片?对于更复杂的版面,我需要确保所有项目都可以显示,我通常从最外层的容器RelativeLayout开始。我用layout_alignParentTop和layout_alignParentBottom(在垂直布局的情况下,您的布局似乎是这样的)停靠需要位于末端的任何东西,然后我努力制作下一组与它们相关的元素。基本上,从边缘开始,以你的方式进入 因此,在您的情况下,按钮应该具有属性android:lay
我的问题:如何缩小显示版面所有元素的图片?对于更复杂的版面,我需要确保所有项目都可以显示,我通常从最外层的容器RelativeLayout开始。我用layout_alignParentTop和layout_alignParentBottom(在垂直布局的情况下,您的布局似乎是这样的)停靠需要位于末端的任何东西,然后我努力制作下一组与它们相关的元素。基本上,从边缘开始,以你的方式进入
因此,在您的情况下,按钮应该具有属性
android:layout\u alignParentBottom=“true”
,电视应该具有android:layout\u over=“@+id/mainscreen\u btchange”
。顶部的文本视图应具有android:layout\u alignParentTop=“true”
,其下方的图像视图应具有android:layout\u below=“@+id/mainscreen”
错误:在包“android”中未找到属性“layout\u aligndown”的资源标识符对不起……这是上面的layout\u和下面的layout\u。我还修复了代码示例,我希望图片显示正确。您的代码对图片没有任何更改“显示正确”是什么意思?这有点模糊。“我的代码”帮助您正确布置控件,使按钮不再隐藏在视图中。我认为,第2步需要适当调整图像的大小,以占用适当的可用空间。这可能需要使用不同的容器。在底部和顶部元素之间可能有一个线性布局(因此,上面的布局和下面的布局都将位于同一个线性布局上),并对子元素使用布局权重,以允许它们在更新新xml时占用适当的剩余空间。新截图:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical">
<TextView android:layout_height="wrap_content" android:id="@+id/mainscreen" android:layout_width="fill_parent" android:text="Selected Channel" android:gravity="center" android:layout_alignParentTop="true"></TextView>
<ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/mainscreen_state" android:layout_above="@+id/mainscreen_btchange"></TextView>
<ImageView android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:layout_height="wrap_content" android:id="@+id/ImageAd" android:layout_gravity="center" android:layout_below="@+id/mainscreen"></ImageView> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="@+id/mainscreen_btchange"
android:text="Change State"></Button>
</RelativeLayout>
</LinearLayout>