imageview 和 textview 之间的巨大差距

Huge gap between imageview and textview

在我的 activity 片段中,有些页面有图像,有些没有。布局是这样的:Textview-Imageview-Textview,所以当我没有图像时,我希望 Textviews 彼此下方。这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#006400">

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="match_parent">
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/handling"
        android:textColor="#ffffff"
        android:textSize="20dp" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:id="@+id/stilling"
        android:layout_below="@id/handling"
        android:layout_gravity="center_vertical" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:textAlignment="center"
                android:text="New Text"
                android:id="@+id/arabisk"
                android:layout_below="@id/stilling"
                android:layout_gravity="center"
                android:textSize="18dp"
                android:textColor="#ff0000" />

        </RelativeLayout>

    </ScrollView>

</LinearLayout>

This is what I get

编辑:

我的图片数组

int[] billede = new int[18];
        billede[1] = R.mipmap.sojle1;
        billede[2] = R.mipmap.sojle4;
        billede[3] = R.mipmap.sojle2;
        billede[4] = R.mipmap.sojle3;
        billede[6] = R.mipmap.sojle4;
        billede[8] = R.mipmap.sojle6;
        billede[10] = R.mipmap.sojle7;
        billede[12] = R.mipmap.sojle8;
        billede[15] = R.mipmap.sojle9;

        stilling.setImageResource(billede[mPage]);

        return view;

将 ImageView 可见性设置为“消失”,并且您的文本视图必须像您想要的那样位于另一个下方。像这样

stilling.setVisibility(View.GONE);

使用 LinearLayout 而不是 RelativeLayout。并设置可见 View.GONE 隐藏 ImageView.

将可见性设置为 GONE

在你的 xml

android:visibility="GONE"

或通过代码

imageView.setVisibility(View.GONE);