簡體   English   中英

如何將點指示器放置在圖像滑塊的底部?

[英]How to position Dot Indicators to be at the bottom of the image slider?

我使用ViewPager創建了圖像滑塊,並且還添加了點指示器以使滑塊更具交互性。 但是,點指示器位於圖像下方,我希望點指示器位於圖像重疊的底部。

下面給出了我的代碼,我在布局中使用了layout:weight元素,因此圖像的高度根據屏幕尺寸而變化。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10"
tools:context="com.example.navigationdrawerfragments.aboutSLFragment">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="4.5">

<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

</LinearLayout>

<LinearLayout
    android:id="@+id/SliderDots"
    android:layout_below="@+id/viewPager"
    android:orientation="horizontal"
    android:gravity="center_vertical|center_horizontal"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.2"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="5.3">

</LinearLayout>


</LinearLayout>

當前結果 當前結果

預期結果 在此處輸入圖片說明

嘗試這樣的事情。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10"
tools:context="com.example.navigationdrawerfragments.aboutSLFragment">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4.5">

<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

<LinearLayout
    android:id="@+id/SliderDots"
    android:layout_below="@+id/viewPager"
    android:orientation="horizontal"
    android:gravity="bottom"
    android:layout_width="match_parent"
    android:layout_height="30dp"/>


</RelativeLayout>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="5.3">

</LinearLayout>


</LinearLayout>

這是針對您的情況最優化的 XML布局

您應該使用相對布局,並且可以像這樣修改XML,可以避免使用權重。 由於重量不適用於相對布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/activity_main"
                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/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    <LinearLayout
        android:id="@+id/SliderDots"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerInParent="true"
        android:layout_marginBottom="25dp"
        android:orientation="horizontal"/>

</RelativeLayout>

您可以將FrameLayout用於這種視圖。您可以在圖像上重疊滑塊點。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/activity_main"
                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/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    <LinearLayout
        android:id="@+id/SliderDots"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerInParent="true"
        android:layout_marginBottom="25dp"
        android:orientation="horizontal"/>

</FrameLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM