2017-09-23 9 views
0

のエッジでImageViewの: imageview centeredアンドロイド - センター私はConstraintLayoutを使用していますが、私は、この画像のようなレイアウトの端にImageViewのを中心にしたいレイアウト

をどのように標高を使用せずにConstraintLayoutを使用することによって、これを達成することができます(私はLollipop以前のデバイスの高度をどう扱うかわかりません)。ここで

は、これまでの私のコードです:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="300dp" 
    app:behavior_hideable="false" 
    app:behavior_peekHeight="190dp" 
    android:clickable="true" 
    android:focusable="true" 
    android:background="#eee" 
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior" 
    android:id="@+id/main_ride_finished_container" 
    > 


    <de.hdodenhof.circleimageview.CircleImageView 
     android:id="@+id/main_driver_enroute_BS_driverImage" 
     android:layout_width="70dp" 
     android:layout_height="70dp" 
     android:src="@color/colorPrimary" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     android:elevation="3dp" 
     /> 
    <android.support.constraint.ConstraintLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="35dp" 
     android:background="#FFFFFF" 
     > 


    </android.support.constraint.ConstraintLayout> 


</android.support.constraint.ConstraintLayout> 
+0

enter image description hereあなたがこれまでに私が – akhilesh0707

+0

をコードを投稿してみてください[これ](http://saulmm.github.io/mastering-coordinator) [this](https://github.com/saulmm/CoordinatorBehaviorExample/blob/master/app/src/main/res/layout/activity_main.xml)に移動します。 – ZeroOne

+0

をusin午前のコードサンプルを追加し、ここでakhilesh0707 @ –

答えて

1

あなたは場所に適切な制約を使用することにより、レイアウトのエッジを中心としたビューを行うことができます。以下の簡単な例では、ImageViewは、囲むコンテナの開始と終了に制約され、水平に配置します。画像ビューの上端と下端は、内側のレイアウトの下端を中心にして下端に拘束されます。これは、ConstraintLayoutが「不可能な」制約をどのように処理するかです。 docを参照してください。

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.constraint.ConstraintLayout 
     android:id="@+id/innerLayout" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:background="@color/colorPrimary" /> 

    <ImageView 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:background="@color/colorAccent" 
     app:layout_constraintBottom_toBottomOf="@id/innerLayout" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toBottomOf="@id/innerLayout" /> 

</android.support.constraint.ConstraintLayout> 
関連する問題