【发布时间】:2026-02-01 20:55:01
【问题描述】:
所以我的问题如下...我有一个具有 3 个主要元素的 RelativeLayout。一列左侧有 2 个按钮,右侧有另一个按钮,中间有一个 ScrollView 布局,其中包含一个 ViewPager 和一个按钮。
按钮与它的父级对齐。但我无法让 ViewPager 自行对齐。
这是我的 XML 布局。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/leftButtons"
android:weightSum="1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dip"
android:orientation="vertical"
android:layout_alignParentStart="true"
>
<Space
android:layout_weight="0.5"
android:layout_width="match_parent"
android:layout_height="0dip" />
<ImageButton
android:id="@+id/leftArrowBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:contentDescription="@string/left_arrow"
android:gravity="center_vertical|center_horizontal"
android:src="@drawable/arrow_left_selector"
android:layout_marginBottom="60dip"
/>
<ImageButton
android:id="@+id/leftArrowBtnAll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:contentDescription="@string/left_arrow"
android:gravity="center_vertical|center_horizontal"
android:src="@drawable/arrow_left_selector_all" />
</LinearLayout>
<ScrollView
android:id="@+id/middleLayouts"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_toRightOf="@+id/leftButtons"
android:layout_toLeftOf="@+id/rightButtons"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="35dip"
android:gravity="center_horizontal"
>
<Button
android:id="@+id/selectDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:background="@drawable/default_button_rounded"
android:drawablePadding="35dip"
android:drawableRight="@drawable/ic_date_light"
android:gravity="center_vertical|center_horizontal"
android:paddingBottom="5dip"
android:paddingLeft="25dip"
android:paddingRight="25dip"
android:paddingTop="5dip"
android:text="@string/monthly_statistics_"
android:textColor="@color/light_bg" />
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_horizontal"
/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/rightButtons"
android:weightSum="1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="10dip"
android:orientation="vertical"
android:layout_alignParentEnd="true"
>
<Space
android:layout_weight="0.5"
android:layout_width="match_parent"
android:layout_height="0dip" />
<ImageButton
android:id="@+id/rightArrowbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:contentDescription="@string/right_arrow"
android:gravity="center_vertical|center_horizontal"
android:src="@drawable/arrow_right_selector"
android:layout_marginBottom="60dip"
/>
<ImageButton
android:id="@+id/rightArrowbtnAll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:contentDescription="@string/right_arrow"
android:gravity="center_vertical|center_horizontal"
android:src="@drawable/arrow_right_selector_all" />
</LinearLayout>
这是它的外观截图......
这是布局编辑器的屏幕截图,显示表格应该对齐......
我尝试了所有类型的布局和重力等。但我无法让它居中! :(
谢谢
【问题讨论】:
标签: android android-layout android-viewpager scrollview android-relativelayout