【发布时间】:2016-10-26 19:38:14
【问题描述】:
我想要这个:一个被 2 个箭头覆盖的 ViewPager
我通过这段代码得到了我想要的东西。但是,我收到了这些 lint 警告:
- 这个布局没用(对于虚拟布局)
- 嵌套权重不利于性能。
我想知道是否有更好的方法来获得我想要的这个 UI。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="@+id/dialog_instruction_pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</android.support.v4.view.ViewPager>
<!-- this LinearLayout overlays the ViewPager -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<!-- This is just the container for the left and right arrows , it is allocated with only 20% of screen height-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".2"
android:orientation="horizontal" >
<!-- I want to align this to the left and set width only 5% of the parent -->
<ImageButton
android:id="@+id/instruction_dialog_left_arrow"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".05"
android:background="?android:attr/selectableItemBackground"
android:scaleType="fitCenter"
android:src="@drawable/arrow_left_grey" />
<!-- This is the dummy layout, standing in the middle of 2 arrows so they can be align to the left and right of the parent -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".8" >
</LinearLayout>
<!-- I want to align this to the right and set width only 5% of the parent-->
<ImageButton
android:id="@+id/instruction_dialog_right_arrow"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".05"
android:background="?android:attr/selectableItemBackground"
android:scaleType="fitCenter"
android:src="@drawable/arrow_right_grey" />
</LinearLayout>
</LinearLayout>
P.S:是否有任何布局允许将子级左、右、下对齐(如 RelativeLayout)并允许将宽度、高度设置为百分比(如 LinearLayout 中的“权重”属性)?
谢谢!
【问题讨论】:
标签: java android android-linearlayout android-layout-weight