[英]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
而不是進行父級加工。 我嘗試了RelativeLayout
和LinearLayout
,沒有太多機會,知道嗎?
<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.