对齐底部在相对布局中无法正常工作
align bottom not working properlly in relative layout
虽然 运行 应用程序布局显示不正确
我正在尝试在引用文本视图下方显示作者文本视图
但它不起作用
XML
<?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"
android:background="@color/black"
tools:context=".PreviewActivity">
<RelativeLayout
android:id="@+id/lnimg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/contact_number"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/imgquote"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/quote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/album_title_padding"
android:paddingRight="@dimen/album_title_padding"
android:textColor="@color/white"
android:text="Quotes"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:typeface="serif"
android:textSize="@dimen/_15sdp" />
<TextView
android:id="@+id/author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:layout_below="@+id/quote"
android:paddingRight="@dimen/album_title_padding"
android:text=" -Author"
android:textColor="@color/white"
android:textSize="@dimen/_15sdp" />
</RelativeLayout>
<ImageView
android:id="@+id/imgsave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/circle"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="@dimen/_5sdp"
android:padding="@dimen/_5sdp"
android:clickable="true"
android:src="@drawable/ic_download"/>
</RelativeLayout>
我以前做过这种布局,但现在不行了
我得到这个输出
非常感谢任何帮助。
按如下方式更改您的 TextView,它将完美运行..
<TextView
android:id="@+id/quote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:gravity="center_horizontal"
android:text="To Sccesssed in life you \n things a wishbone, a backbone and \n a funny bone."
android:textColor="#000000"
android:textSize="15sp"
android:typeface="serif" />
<TextView
android:id="@+id/author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/quote"
android:gravity="bottom|right"
android:paddingRight="20dp"
android:text=" -Author"
android:textColor="#000000"
android:textSize="15sp" />
删除这个
android:layout_centerInParent="true"
你引用了 TextView。
你可以试试这个:
<?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"
android:background="@color/black"
tools:context=".PreviewActivity">
<RelativeLayout
android:id="@+id/lnimg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/contact_number"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/imgquote"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/quote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/album_title_padding"
android:paddingRight="@dimen/album_title_padding"
android:textColor="@color/white"
android:text="Quotes"
android:gravity="center_horizontal"
android:typeface="serif"
android:textSize="@dimen/_15sdp" />
<TextView
android:id="@+id/author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:layout_below="@+id/quote"
android:paddingRight="@dimen/album_title_padding"
android:text=" -Author"
android:textColor="@color/white"
android:textSize="@dimen/_15sdp" />
</RelativeLayout>
<ImageView
android:id="@+id/imgsave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/circle"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="@dimen/_5sdp"
android:padding="@dimen/_5sdp"
android:clickable="true"
android:src="@drawable/ic_download"/>
</RelativeLayout>
解决问题
只需在垂直 LinearLayout 中移动 Textview
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical">
<TextView
android:id="@+id/quote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/album_title_padding"
android:paddingRight="@dimen/album_title_padding"
android:paddingTop="@dimen/album_title_padding"
android:gravity="center_horizontal"
android:textColor="@color/white"
android:text="Quotes"
android:typeface="serif"
android:textSize="@dimen/_15sdp" />
<TextView
android:id="@+id/author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:paddingLeft="@dimen/album_title_padding"
android:paddingRight="@dimen/album_title_padding"
android:paddingTop="@dimen/album_title_padding"
android:layout_marginTop="@dimen/_10sdp"
android:layout_marginBottom="@dimen/_5sdp"
android:text=" -Author"
android:textColor="@color/white"
android:textSize="@dimen/_15sdp" />
</LinearLayout>
虽然 运行 应用程序布局显示不正确
我正在尝试在引用文本视图下方显示作者文本视图
但它不起作用
XML
<?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"
android:background="@color/black"
tools:context=".PreviewActivity">
<RelativeLayout
android:id="@+id/lnimg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/contact_number"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/imgquote"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/quote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/album_title_padding"
android:paddingRight="@dimen/album_title_padding"
android:textColor="@color/white"
android:text="Quotes"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:typeface="serif"
android:textSize="@dimen/_15sdp" />
<TextView
android:id="@+id/author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:layout_below="@+id/quote"
android:paddingRight="@dimen/album_title_padding"
android:text=" -Author"
android:textColor="@color/white"
android:textSize="@dimen/_15sdp" />
</RelativeLayout>
<ImageView
android:id="@+id/imgsave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/circle"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="@dimen/_5sdp"
android:padding="@dimen/_5sdp"
android:clickable="true"
android:src="@drawable/ic_download"/>
</RelativeLayout>
我以前做过这种布局,但现在不行了
我得到这个输出
非常感谢任何帮助。
按如下方式更改您的 TextView,它将完美运行..
<TextView
android:id="@+id/quote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:gravity="center_horizontal"
android:text="To Sccesssed in life you \n things a wishbone, a backbone and \n a funny bone."
android:textColor="#000000"
android:textSize="15sp"
android:typeface="serif" />
<TextView
android:id="@+id/author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/quote"
android:gravity="bottom|right"
android:paddingRight="20dp"
android:text=" -Author"
android:textColor="#000000"
android:textSize="15sp" />
删除这个
android:layout_centerInParent="true"
你引用了 TextView。
你可以试试这个:
<?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"
android:background="@color/black"
tools:context=".PreviewActivity">
<RelativeLayout
android:id="@+id/lnimg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/contact_number"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/imgquote"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/quote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/album_title_padding"
android:paddingRight="@dimen/album_title_padding"
android:textColor="@color/white"
android:text="Quotes"
android:gravity="center_horizontal"
android:typeface="serif"
android:textSize="@dimen/_15sdp" />
<TextView
android:id="@+id/author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:layout_below="@+id/quote"
android:paddingRight="@dimen/album_title_padding"
android:text=" -Author"
android:textColor="@color/white"
android:textSize="@dimen/_15sdp" />
</RelativeLayout>
<ImageView
android:id="@+id/imgsave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/circle"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="@dimen/_5sdp"
android:padding="@dimen/_5sdp"
android:clickable="true"
android:src="@drawable/ic_download"/>
</RelativeLayout>
解决问题
只需在垂直 LinearLayout 中移动 Textview
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical">
<TextView
android:id="@+id/quote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/album_title_padding"
android:paddingRight="@dimen/album_title_padding"
android:paddingTop="@dimen/album_title_padding"
android:gravity="center_horizontal"
android:textColor="@color/white"
android:text="Quotes"
android:typeface="serif"
android:textSize="@dimen/_15sdp" />
<TextView
android:id="@+id/author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:paddingLeft="@dimen/album_title_padding"
android:paddingRight="@dimen/album_title_padding"
android:paddingTop="@dimen/album_title_padding"
android:layout_marginTop="@dimen/_10sdp"
android:layout_marginBottom="@dimen/_5sdp"
android:text=" -Author"
android:textColor="@color/white"
android:textSize="@dimen/_15sdp" />
</LinearLayout>