我想将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)
只需使用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>