[英]How to center a LinearLayout in RealativeLayout
我試圖將LinearLayout(在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"
android:background="@drawable/main_background"
tools:context=".SlideActivity"
android:layout_centerInParent="true">
<android.support.v4.view.ViewPager
android:id="@+id/slideViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"></android.support.v4.view.ViewPager>
<LinearLayout
android:id="@+id/dotsLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/slideViewPager"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
android:orientation="horizontal"
android:padding="20dp"
android:layout_gravity="center" />
</RelativeLayout>
https://drive.google.com/file/d/1MjhGpGhqBM_SJa1j3soEL31ZzoAkf6pg/view?usp=sharing底部的3個點應居中 。 然而他們堅持左翼......
只需刪除此行:
android:layout_alignParentStart="true"
所以你的布局不會粘貼(對齊)父母的開頭(在你的情況下是左邊),因為你已經有:
android:layout_centerInParent="true"
您的LinearLayout
將位於屏幕的中心。
不要使用“layout_alignParentStart = true” - 這似乎與“layout_centerInParent = true”沖突。
你必須刪除所有類型的對齊屬性,只保留這個:
android:layout_centerInParent="true
試試這個
<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="@drawable/main_background"
tools:context=".SlideActivity">
<android.support.v4.view.ViewPager
android:id="@+id/slideViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
/>
<LinearLayout
android:layout_below="@id/slideViewPager"
android:id="@+id/dotsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="horizontal"
android:padding="20dp"/>
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.