2017-07-02 74 views
0

我想將ImageViews拉伸到parentlayout。我已經用marginleft命令完成了它。但對於不同的屏幕它沒有用處。在一個佈局中拉伸幾個視圖

我不想用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。

+0

然後用重量線性佈局。 –

回答

1

這可以很容易地完成只有約束佈局,你將不需要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> 
相關問題