![](/img/trans.png)
[英]layout_alignParentRight not working for relative layout inside linear layout
[英]Layout_alignParentRight and others aren't working
我只是想通過制作生日賀卡應用程序來完成 Udacity 上的第一堂應用程序制作課程。 它要求我將“來自你的名字”放在生日賀卡的右下角。 我嘗試使用android:layout_alignParentRight
和android:layout_alignParentBottom
並且沒有任何改變。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Happy Birthday friendName!"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:text="From yourName!"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/androidparty" />
如果你想使用android:layout_alignParentRight
和android:layout_alignParentBottom
那么
使用RelativeLayout
作為根布局
示例代碼
<?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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Happy Birthday friendName!"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:text="From yourName!"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/androidparty" />
</RelativeLayout>
當父布局為RelativeLayout
時使用的android:layout_alignParentBottom
和android:layout_alignParentRight
屬性,這兩個屬性不適用於ConstraintLayout
只需將您的根布局更改為RelativeLayout
它將起作用
示例代碼
<?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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Happy Birthday friendName!"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:text="From yourName!"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/androidparty" />
</RelativeLayout>
android:layout_alignParentRight
或android:layout_alignParentBottom
與 RelativeLayout 一起使用
對於約束布局,您必須使用
app:layout_constraintRight_toRightOf="parent"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.