关于我的片段活动,我有一些页面有图像,有些没有。布局是这样的:Textview-Imageview-Textview,所以当我没有图像时,我希望文本视图彼此下方。这是我的 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>
这就是我得到的
编辑:
我的图像数组
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;
将可见性设置为GONE
在您的 XML 中
android:visibility="GONE"
或通过代码
imageView.setVisibility(View.GONE);
将 ImageView 可见性设置为"消失",并且您的文本视图必须像您想要的那样低于另一个。喜欢这个
stilling.setVisibility(View.GONE);
使用 LinearLayout 而不是 RelativeLayout
。并设置可见的View.GONE以隐藏ImageView
。