2017-07-02 10 views
0

ImageViewsをparentlayoutにストレッチしたい。私はmarginleftコマンドでやった。しかし、それは別の画面では役に立ちません。1つのレイアウトでいくつかのビューを伸ばす

私はマージンをjavaで変更したくありません。私はそれらのImageviewsすべての画面のためにストレッチしたいと思います。彼らはこれのための任意のコマンドですか?

<?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" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.berkay.uumobil.MainActivity"> 

<RelativeLayout 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    tools:layout_constraintBottom_creator="1" 
    tools:layout_constraintLeft_creator="1" 
    tools:layout_constraintRight_creator="1" 
    tools:layout_constraintTop_creator="1"> 


    <LinearLayout 
     android:id="@+id/menuLayout" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:background="@color/colorPrimary" 
     android:orientation="horizontal"> 

     <ImageView 
      android:id="@+id/menu_home" 
      android:layout_width="32dp" 
      android:layout_height="32dp" 
      android:layout_gravity="center" 
      android:layout_marginLeft="10dp" 
      app:srcCompat="@drawable/home_button" /> 

     <ImageView 
      android:id="@+id/menu_marks" 
      android:layout_width="32dp" 
      android:layout_height="32dp" 
      android:layout_gravity="center" 
      android:layout_marginLeft="30dp" 
      app:srcCompat="@drawable/not_karti_button" /> 

     <ImageView 
      android:id="@+id/menu_calender" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:layout_gravity="center" 
      android:layout_marginLeft="30dp" 
      app:srcCompat="@drawable/takvim_button" /> 

     <ImageView 
      android:id="@+id/menu_timetable" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:layout_gravity="center" 
      android:layout_marginLeft="30dp" 
      app:srcCompat="@drawable/dersprog_button" /> 

     <ImageView 
      android:id="@+id/menu_foodlist" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:layout_gravity="center" 
      android:layout_marginLeft="30dp" 
      app:srcCompat="@drawable/yemek_button" /> 

     <ImageView 
      android:id="@+id/menu_logout" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:layout_gravity="center" 
      android:layout_marginLeft="30dp" 
      app:srcCompat="@drawable/logout_button" /> 

    </LinearLayout> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/menuLayout" 
     android:layout_alignParentTop="true"> 


    </FrameLayout> 

</RelativeLayout> 

In this picture ImageViews are not stretched

In this picture ImageViews are stretched via marginLeft

私はmarginleftを使用せずに、第2のように自分のアプリケーションを見てみたいです。

+0

。 –

答えて

1

これは、Constraintレイアウトのみで簡単に行うことができ、RelativeLayoutは必要ありません。

https://developer.android.com/training/constraint-layout/index.html#constrain-chain

あなたのレイアウトはのようになります。制約のチェーンを使用した:リニアレイアウトで重量を使用し、その後

<?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:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <FrameLayout 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_marginBottom="0dp" 
     android:layout_marginLeft="0dp" 
     android:layout_marginRight="0dp" 
     android:layout_marginTop="0dp" 
     android:background="@color/colorPrimary" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/frameLayout"> 

    </FrameLayout> 

    <ImageView 
     android:id="@+id/menu_home" 
     android:layout_width="48dp" 
     android:layout_height="48dp" 
     app:srcCompat="@drawable/ic_lock_black_24dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintLeft_toRightOf="@+id/menu_marks" /> 

    <ImageView 
     android:id="@+id/menu_marks" 
     android:layout_width="48dp" 
     android:layout_height="48dp" 
     app:srcCompat="@drawable/ic_lock_black_24dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintRight_toLeftOf="@+id/menu_home" 
     app:layout_constraintLeft_toRightOf="@+id/menu_calender" /> 

    <ImageView 
     android:id="@+id/menu_calender" 
     android:layout_width="48dp" 
     android:layout_height="48dp" 
     app:srcCompat="@drawable/ic_lock_black_24dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintRight_toLeftOf="@+id/menu_marks" 
     app:layout_constraintLeft_toRightOf="@+id/menu_timetable" /> 

    <ImageView 
     android:id="@+id/menu_timetable" 
     android:layout_width="48dp" 
     android:layout_height="48dp" 
     app:srcCompat="@drawable/ic_lock_black_24dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintRight_toLeftOf="@+id/menu_calender" 
     app:layout_constraintLeft_toRightOf="@+id/menu_foodlist" /> 

    <ImageView 
     android:id="@+id/menu_foodlist" 
     android:layout_width="48dp" 
     android:layout_height="48dp" 
     app:srcCompat="@drawable/ic_lock_black_24dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintRight_toLeftOf="@+id/menu_timetable" 
     app:layout_constraintLeft_toRightOf="@+id/menu_logout" /> 

    <ImageView 
     android:id="@+id/menu_logout" 
     android:layout_width="48dp" 
     android:layout_height="48dp" 
     app:srcCompat="@drawable/ic_lock_black_24dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@+id/menu_foodlist" /> 

    <FrameLayout 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_alignParentTop="true" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintBottom_toTopOf="@+id/menu_logout" 
     app:layout_constraintHorizontal_bias="1.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintVertical_bias="1.0" 
     android:layout_marginTop="0dp" 
     android:id="@+id/frameLayout"/> 

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