LinearLayout中的Imageview layout_weight运行不正常

时间:2015-05-27 22:23:29

标签: bitmap imageview android-layout-weight scaletype

我正在制作包含肖像和风景的视图。

在肖像方面,我的代码运行正常。

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        />
    <LinearLayout
        android:id="@+id/text_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:orientation="vertical"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

    </LinearLayout>
  </LinearLayout></ScrollView>

图像与上述代码完美显示。

然而,在风景中。我有:

<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/image"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:layout_margin="10dp"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    />

<ScrollView 
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1">
        <LinearLayout
            android:id="@+id/text_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:orientation="vertical"
            android:visibility="gone">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
             />

        </LinearLayout>
</ScrollView>
</LinearLayout>

图像无法完美显示。它只显示图像的很小一部分。我尝试了所有scaleType属性,但它们都不起作用。

你们有什么想法吗?感谢。

1 个答案:

答案 0 :(得分:0)

您正在使用android:scaleType="centerCrop"

- 所以你的形象会从中心被歪起来,它会显示出来...... - 但是你想要它的全宽和高度......

我的建议是使用android:scaleType="FITXY"