我想在屏幕中间显示一些文本,位于页眉和页脚下方。由于这段文字非常长,我将它嵌套在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