2

私のxmlデザインに問題があります。私は自分のアプリケーションにViewpagerを加え、ツー​​ルバーをアプリケーションの上に追加しました。ですから、私の問題は、私のViewpagerに属するフラグメントから重力中心のアイテムを中心にしようとすると、Viewpagerの中央に設定され、Toolbarの高さは無視されます。親ビューで画面全体を塗りつぶしていない場合のフラグメントの中心項目

私は親ビューが画面全体を満たしていないときに、画面の中央にあるビューまたはフラグメントからアイテムをセンターすることが可能かどうかを尋ねたいと思います。

私の活動のXMLはこの1つである:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

<include layout="@layout/toolbar" 
    android:id="@+id/toolbar"></include> 

<com.example.android.ui.SlidingTabLayout 
    android:id="@+id/module_selector_tabs" 
    android:layout_width="match_parent" 
    android:layout_height="48dp" 
    android:background="@color/view_pager_top" 
    android:layout_below="@id/toolbar" 
    android:elevation="4dp"/> 
<android.support.v4.view.ViewPager 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/viewPager" 
    android:layout_below="@id/module_selector_tabs" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    /> 

</RelativeLayout> 

私がセンターにしたい項目は、私がFragmentAdapterでViewpagerにdinamically追加フラグメントの内側にあります。誰かがこれを行う方法を知っていることを願っています! enter image description here

敬具:私はちょうどタイマーテキスト& CircleProgressBarが、今、彼らはviewpagerの中老に合わせている全画面の中央にしたい、のような

今私のアプリが見えます!

+0

あなたが望むスクリーンショットを投稿できますか? –

+0

写真が追加され、もう少し定義が追加されました –

答えて

0

最後に、レイアウトを上に移動して、私が望む結果を得ることができました!

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/fragment_background" 
android:orientation="vertical"> 


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/countdownLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/buttons_layout"> 

    <com.example.android.voicetimer.ui.CircleProgressBar 
     android:id="@+id/progressBar" 
     style="?android:attr/progressBarStyleHorizontal" 
     android:layout_width="@dimen/progressbar_size" 
     android:layout_height="@dimen/progressbar_size" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:gravity="center" 
     android:progressDrawable="@drawable/circular" /> 

    <Spinner 
     android:id="@+id/timer_name_picker" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAlignment="center" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:gravity="center" 
     style="@style/medium_light_hms" 
     android:layout_above="@+id/timerText" /> 


    <com.example.android.voicetimer.ui.HmsView 
     android:id="@+id/timerText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:gravity="center"> 

     <com.example.android.voicetimer.ui.ZeroTopPaddingTextView 
      android:id="@+id/hours_ones" 
      style="@style/medium_light_hms" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ellipsize="none" 
      android:singleLine="true" 
      android:visibility="gone" /> 

     <TextView 
      android:id="@+id/hours_label" 
      style="@style/fragment_label" 
      android:padding="0dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top" 
      android:ellipsize="none" 
      android:singleLine="true" 
      android:text="@string/hms_picker_hours_label" 
      android:visibility="gone" /> 

     <com.example.android.voicetimer.ui.ZeroTopPaddingTextView 
      android:id="@+id/minutes_tens" 
      style="@style/medium_light_hms" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ellipsize="none" 
      android:singleLine="true" 
      android:visibility="gone" /> 

     <com.example.android.voicetimer.ui.ZeroTopPaddingTextView 
      android:id="@+id/minutes_ones" 
      style="@style/medium_light_hms" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ellipsize="none" 
      android:singleLine="true"/> 

     <TextView 
      android:id="@+id/minutes_label" 
      style="@style/fragment_label" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top" 
      android:ellipsize="none" 
      android:singleLine="true" 
      android:text="@string/hms_picker_minutes_label" /> 

     <com.example.android.voicetimer.ui.ZeroTopPaddingTextView 
      android:id="@+id/seconds_tens" 
      style="@style/medium_light_hms" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ellipsize="none" 
      android:singleLine="true" /> 

     <com.example.android.voicetimer.ui.ZeroTopPaddingTextView 
      android:id="@+id/seconds_ones" 
      style="@style/medium_light_hms" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ellipsize="none" 
      android:singleLine="true"/> 

     <TextView 
      android:id="@+id/seconds_label" 
      style="@style/fragment_label" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top" 
      android:ellipsize="none" 
      android:singleLine="true" 
      android:text="@string/hms_picker_seconds_label" /> 
    </com.example.android.voicetimer.ui.HmsView> 
</RelativeLayout> 


<LinearLayout 
    android:id="@+id/buttons_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:gravity="center_horizontal" 
    android:orientation="horizontal" 
    android:clipChildren="false"> 

    <ImageView 
     android:id="@+id/btnDelete" 
     android:layout_width="@dimen/delete_button_size" 
     android:layout_height="@dimen/delete_button_size" 
     android:layout_gravity="center" 
     android:layout_margin="@dimen/icon_margin" 
     android:layout_weight="1" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     android:src="@drawable/ic_delete_black" 
     android:tint="@color/icon_tint" /> 
1

これは、Viewpagerではなくフラグメントに関するものです。フラグメントのレイアウトを貼り付けることはできますか?

イメージから、私は、垂直の線形レイアウトで、2つの子、円の最初のものとボタンのもう1つを持ちます。

次に、layout_weightを使用して、子の開始と終了の場所を制御できます。 layout_weightについて

詳細情報: https://developer.android.com/guide/topics/ui/layout/linear.html#Weight

すみませんが、私は今、レイアウトエディタを持っていません。

関連する問題