java - 如何在 RealativeLayout 中将 LinearLayout 居中
问题描述
我正在尝试将 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 个点应该居中。但是他们坚持向左...
解决方案
试试这个
<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>
推荐阅读
- c# - 执行单击网格中的按钮
- python-3.x - 按名称排序对象并按编号排序
- angular - 用于处理 Hadoop 数据的 UI 框架
- amazon-web-services - Velostrata 从 AWS 迁移到 GCP 失败:[云实例启动失败]
- python - 如何在python中实现反向引用?
- javascript - 如何在 JavaScript 中创建一个完全独立的对象实例
- javascript - 访问动态创建的组件的 prop
- elasticsearch - min_doc_freq 如何在 More Like This 查询中工作?
- python - 是否有适用于 use_multiprocessing=True 的 fit_generator 的工作示例?
- javascript - 如何让 Javascript 下载特定的媒体文件类型?