Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – How to avoid unnecessary Relative layout in Linear Layout

Posted on November 11, 2022 By

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

READ  [FIXED] java - How to see res/drawable-nodpi/ folder in Android Studio
Powered by Inline Related Posts
Android Tags:android, android-layout, layout, xml

Post navigation

Previous Post: [FIXED] android – LottieAnimationView doesn’t show in my_layout.xml
Next Post: [FIXED] android – Firestore conditional array query

Related Posts

[FIXED] android – Why can’t nativescript-geolocation resolve when building an APK for release? Android
[FIXED] android – Creating a layout with mutiple Imageviews behind one another Android
[FIXED] Autocomplete not working correctly in Android Studio with Flutter – First suggestions are irrelevant Android
[FIXED] Can’t build android app due to ClassNotFoundException Android
[FIXED] android – How to change str(nparray) to original nparray with UDP in python Android
[FIXED] Linking static “.a” libraries to an Android Studio project using Gradle and CMake Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can VPN be traced by police?
  • Where were Kaiser-Frazer cars built?
  • How do you make gold rose gold paint?
  • What are the newest type of dentures?
  • Can you wear joggers as dress pants?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme