我想在屏幕中間顯示一些文本,位於頁眉和頁腳下方。由於這段文字非常長,我將它嵌套在ScrollView中。我已經嘗試了一些解決方案:this,this,this,this,和一幫更多...Android,layout_above不能正常工作
起初我有兩個relative_layouts重疊和文本被切的問題。最接受的答案是使用layout_above
和layout_below
,但是當我使用layout_above時,文本從不顯示。
這是我的XML是什麼樣子:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/linear_layout_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/gray"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="3">
<ImageView
android:id="@+id/profile_image"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_margin="10dp"
android:contentDescription="@string/profile_photo"
android:src="@drawable/default_profile"
tools:ignore="RtlHardcoded" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/scrollViewAndStuff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_above="@+id/ln_layout_footer"
android:layout_below="@+id/linear_layout_header">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
tools:ignore="UselessParent">
<TextView
android:id="@+id/meetupDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/text"/>-
</ScrollView>
</RelativeLayout>
<RelativeLayout
android:id="@+id/ln_layout_footer"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="horizontal"
android:paddingTop="10dp">
<LinearLayout
android:id="@+id/ln_layout"
android:layout_width="fill_parent"
android:background="@color/gray"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp">
<TextView
android:id="@+id/red"
android:textColor="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/red" />
<TextView
android:id="@+id/blue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@color/white"
android:layout_weight="1"
android:gravity="center"
android:text="@string/blue" />
<TextView
android:id="@+id/green"
android:layout_width="match_parent"
android:textColor="@color/white"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/green" />
</LinearLayout>
</RelativeLayout>
嘗試將您的RelativeLayout與xml結尾處的文本(在您的頁腳之後) – Rachit
嘗試僅使用android:layout_above =「@ id/ln_layout_footer」,+用於將新ID分配給查看 – Hmm
@Rachit試過了,同樣的問題... – Kemo