簡體   English   中英

如何在ViewPager中將固定大小的視圖居中?

[英]How to center a fixed sized view in a ViewPager?

在過去的幾個小時里,我一直在Android上遇到一個非常基本的問題。 我無法在其容器中創建ViewPager視圖內容中心。 這是我的代碼:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:orientation="vertical"
        android:background="#FF0000FF">

    ...

    </LinearLayout>

</FrameLayout>

因此該視圖可以正確顯示在我的ViewPager但不會居中。 通過在FrameLayout上設置顏色,看起來它包裝了LinearLayout而不是進行父級加工。 我嘗試了RelativeLayoutLinearLayout ,沒有太多機會,知道嗎?

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerInParent="true"
        android:orientation="vertical"
        android:background="#FF0000FF">

    ...

    </LinearLayout>

</RelativeLayout>

嘗試這個

暫無
暫無

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

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