【发布时间】:2016-03-08 14:55:05
【问题描述】:
在我的片段活动中,我有一些页面有图像,而有些则没有。布局是这样的: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>
编辑:
我的图片数组
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 -
如何在我的阵列中做到这一点? (已上传)我不会写
billede[13] = stilling.GONE -
您将图像视图设置为消失而不是位图
-
我试过了
android:visibility="gone",但这会删除所有图片 -
好吧,因为您将可见性设置为消失,如果您正在循环浏览图像并显示它们,您需要添加逻辑以仅在有图像时显示图像
标签: android android-layout android-imageview textview