Android 安卓布局;图像占据整个屏幕
我试图用两个视图填充活动,一个是左侧的Android 安卓布局;图像占据整个屏幕,android,android-layout,android-layout-weight,Android,Android Layout,Android Layout Weight,我试图用两个视图填充活动,一个是左侧的ImageView,另一个是右侧的TextView。图像的大小应能填满整个垂直空间。文本应该占据剩余的任何空间。在看了一些教程之后,我似乎需要一个水平方向的线性布局,并且文本视图的布局权重属性为正整数 这就是我到目前为止所做的: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/
ImageView
,另一个是右侧的TextView
。图像的大小应能填满整个垂直空间。文本应该占据剩余的任何空间。在看了一些教程之后,我似乎需要一个水平方向的线性布局
,并且文本视图
的布局权重
属性为正整数
这就是我到目前为止所做的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/charsheet" />
<TextView
android:id="@+id/ipsum"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/ipsum" />
</LinearLayout>
然而,问题是,图像在左右两侧产生了空白,填满了整个屏幕。没有空间可供文本视图使用
我还尝试使用RelativeLayout
,将ImageView
的toStartOf
属性设置为TextView
的id,但随后文本填充整个屏幕
当我开始做这项活动的时候,我不会想到这会是一件如此复杂的事情,但我们到了。任何帮助都将不胜感激。将android:layout_weight=“1”
移动到ImageView,并在TextView中使权重为0。注意:您需要将ImageView的布局宽度设置为0px
<ImageView
android:id="@+id/imageView"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/ipsum"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="ipsum" />
将android:layout_weight=“1”
移动到ImageView,并在TextView中使权重为0。注意:您需要将ImageView的布局宽度设置为0px
<ImageView
android:id="@+id/imageView"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/ipsum"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="ipsum" />
您可以使用ImageView缩放类型,如:
android:scaleType="fitCenter"
您可以使用ImageView缩放类型,如:
android:scaleType="fitCenter"
我认为您缺少的是调整ImageView上的ViewBounds。试着这样做:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:src="@drawable/doug"
/>
<TextView
android:id="@+id/ipsum"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="ipsum"
/>
</LinearLayout>
如果没有adjustImageBounds,ImageView将占用比显示图像所需的更多空间
上面的布局在Android Studio中创建了一个预览,对我来说是这样的:
我认为您缺少的是调整ImageView上的ViewBounds。试着这样做:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:src="@drawable/doug"
/>
<TextView
android:id="@+id/ipsum"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="ipsum"
/>
</LinearLayout>
如果没有adjustImageBounds,ImageView将占用比显示图像所需的更多空间
上面的布局在Android Studio中创建了一个预览,对我来说是这样的:
您想将图像裁剪为适合还是调整大小以适合?我想是调整了大小。我想看到整个图像,减去被添加的空白。你想图像被裁剪以适合还是调整大小以适合?我想是调整大小了。我想看到整个图像,只需减去正被添加的空白,这会导致文本完全填满屏幕,留下图像隐藏。我忘记了布局宽度:0px,立即尝试现在图像不缩放,整个屏幕被部分图像填充。这会导致文本完全填满屏幕,保留图像隐藏我忘记了布局宽度:0px,立即尝试现在图像没有缩放,整个屏幕被图像的一部分填充。这似乎没有任何效果这在Android studio 3.0中不起作用。我刚试过。背景是黑色的,文本视图要小得多。它在Android studio 3.0中不起作用。我刚试过。背景是黑色的,文本视图要小得多。