Я хочу разделить свой экран на 3 равные по вертикали части и добавить ImageView в верхнюю часть. Когда я добавлю изображение, части не будут равны.
Его нельзя изменить с помощью веса макета.
<LinearLayout 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"
app:layout_behavior = "@string/appbar_scrolling_view_behavior"
tools:context = ".MainActivity"
android:orientation = "vertical"
tools:showIn = "@layout/app_bar_main"
android:paddingLeft = "30dp"
android:paddingRight = "30dp">
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_weight = "1">
<ImageView
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:src = "@drawable/logo1"/>
</LinearLayout>
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_weight = "1">
</LinearLayout>
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_weight = "1">
</LinearLayout>
Вам нужно установить android:layout_height = "0dp" во всех LinearLayout, например:
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "0dp"
android:layout_weight = "1">
</LinearLayout>
попробуй это
<LinearLayout 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"
app:layout_behavior = "@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "0dp"
android:layout_weight = "1"
android:background = "#ff0000">
<ImageView
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:scaleType = "fitXY"
android:src = "@drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "0dp"
android:layout_weight = "1"
android:background = "#00ff00">
</LinearLayout>
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "0dp"
android:layout_weight = "1"
android:background = "#0000ff">
</LinearLayout>
ВЫХОД