Android ImageView填充剩余空间
我正在使用ImageView和HorizontalScrollView创建布局。如下图所示 当用户单击HorizontalScrollView中的一个图像时,它将在ImageView中显示更大的图像 到目前为止,我的代码如下Android ImageView填充剩余空间,android,Android,我正在使用ImageView和HorizontalScrollView创建布局。如下图所示 当用户单击HorizontalScrollView中的一个图像时,它将在ImageView中显示更大的图像 到目前为止,我的代码如下 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/imageViewTop"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<HorizontalScrollView
android:id="@+id/mainHorizontalScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/orange"
>
<ImageView
android:id="@+id/image1"
android:layout_width="150dp"
android:layout_height="150dp"
android:scaleType="fitXY"
android:src="@drawable/pic1"
android:padding="15dp"
></ImageView>
<ImageView
android:id="@+id/image2"
android:layout_width="150dp"
android:layout_height="150dp"
android:scaleType="fitXY"
android:src="@drawable/pic2"
android:padding="15dp"
></ImageView>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
上面的代码使ImageView填充整个屏幕..我想要的是ImageView填充未被HorizontalScrollView填充的剩余屏幕。。如何执行此操作???将
图像视图更改为:
<ImageView
android:id="@+id/imageViewTop"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight=1
android:layout_alignParentTop="true"
/>
并使父视图成为一个线性布局
将父布局更改为线性布局,并在ImageView和子RelativeLayout上添加使用权重,如下所示
<LinearLayout ....
......>
<ImagView layout-weight="1"...
...../>
<RelativeLayout layout-weight="0.6"..
......>
<!-- child Views -->
</RelativeLayout>
</LinearLayout>
根据您的要求更改权重值,希望这有助于在布局中使用权重总和和布局权重。还可以使用线性布局作为父布局。还需要将父视图设置为垂直方向。