Solution 1 :
Use below code, imageView is only half the screen:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android_layout_width="match_parent"
android_layout_height="match_parent"
android_orientation="vertical"
android_weightSum="2"
xmlns_tools="http://schemas.android.com/tools"
xmlns_android="http://schemas.android.com/apk/res/android">
<ImageView
android_layout_width="match_parent"
android_layout_height="0dp"
android_layout_weight="1"
android_background="@drawable/img"
android_scaleType="fitXY"
tools_ignore="ContentDescription" />
</LinearLayout>
Problem :
I am using a Linear Layout to display an ImageView and to make it be displayed only one half of the screen. What I have done is to add a Relative layout inside this Linear Layout so that this ImageView only occupies one half of the screen. I am getting a warning as it is normal because this Relative Layout doen’t have any children but I have used it only to occupy the other half of the screen. How could I make the same result avoiding this warning?
This is what I have:
<LinearLayout
android_layout_width="match_parent"
android_layout_height="match_parent"
android_orientation="vertical"
android_weightSum="2">
<ImageView
android_layout_width="match_parent"
android_layout_height="match_parent"
android_layout_weight="1"
android_background="@drawable/img"
android_scaleType="fitXY"
tools_ignore="ContentDescription" />
<RelativeLayout
android_layout_width="match_parent"
android_layout_height="match_parent"
android_layout_weight="1" >
Comments
Comment posted by Cheticamp
Make the
Comment posted by Gabe Sechan
Have you considered switching to a ConstraintLayout?
Comment posted by schemas.android.com/tools
One question, why are you using
Comment posted by Mert
You just shared that part of your code, so i assumed it’s your only code and added that lines. In your case delete them and have it in only parent layout.
Comment posted by Lechius
If the Relative Layout weight was for example 1.5 instead of 1, according to your awnser, I would have to delete the Relative Layout and later assign ImageView layout_weight: 1.5 and Image View layout_height:0dp Is that right?
Comment posted by Mert
The code