Android 如何在坐标系布局中对齐相对线布局底部的线性布局
我有一个相对坐标和一个线性坐标。我要对齐RelativeLayout底部的LinearLayout。但是下面的布局在这里不起作用。我不知道如何实现这一点 这是我的密码Android 如何在坐标系布局中对齐相对线布局底部的线性布局,android,xml,Android,Xml,我有一个相对坐标和一个线性坐标。我要对齐RelativeLayout底部的LinearLayout。但是下面的布局在这里不起作用。我不知道如何实现这一点 这是我的密码 <android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="wrap_content">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/top"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:src="@drawable/artboard_signup"
android:scaleType="fitXY"
android:visibility=""
/>
</RelativeLayout>
<LinearLayout
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="170dp">
<LinearLayout
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Top Bootable Antivirus For Your PC?"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8 hours ago"
android:paddingLeft="10dp"/>
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
我希望id为bottom的LinearLayout位于id为top的RelativeLayout的底部
无论如何,我都可以做到这一点。尝试在
android:id=“@+id/bottom”
之后添加android:layout\u gravity=“bottom”使用RelativeLayout而不是CoordinateLayout,然后在LearLayout中添加行“android:layout\u alignParentBottom=“true”
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/top"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
app:srcCompat="@drawable/ic_call_black_24dp"
android:scaleType="fitXY"
android:visibility="visible"
/>
</RelativeLayout>
<LinearLayout
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="170dp"
android:layout_alignParentBottom="true">
<LinearLayout
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Top Bootable Antivirus For Your PC?"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8 hours ago"
android:paddingLeft="10dp"/>
</LinearLayout>
</LinearLayout>
可能是这样,这样做会奏效。试试看
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/top"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:scaleType="fitXY"
android:src="@drawable/artboard_signup"
android:visibility="" />
<LinearLayout
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="170dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="7"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="15dp"
android:paddingRight="10dp"
android:text="Top Bootable Antivirus For Your PC?" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="8 hours ago" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
解决方案:
只需在
中添加一个
,如下所示:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
orientation:"vertical">
<RelativeLayout
android:id="@+id/top"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:src="@drawable/artboard_signup"
android:scaleType="fitXY"
android:visibility=""
/>
</RelativeLayout>
<LinearLayout
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="170dp">
<LinearLayout
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Top Bootable Antivirus For Your PC?"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8 hours ago"
android:paddingLeft="10dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
希望它能起作用。添加一个线性布局,方向垂直,然后在其内部添加相对和线性,它将自动位于彼此下方。你的线性布局已经在相对布局的底部了吗?@mañgßrmå在你的想法起作用时,我没有这样想。thanks@Sivaperumal我已经发布了一个解决方案,如果你能接受,我会很高兴的。:)你应该提到像这样的小回答作为评论。@Ümañgßürmån我不同意。如果答案足够清楚,不需要太长。我不知道这是不是一个真实的答案。@Kilazur谢谢你的意见。