Why is ImageView not showing in full screen?

I am running an Android project. Why are Image1 ids iv1 and iv2 not displayed in full screen? I posted the XML here:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout1" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingBottom="10px" android:paddingLeft="10px" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:id="@+id/iv1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:visibility="invisible" /> <ImageView android:id="@+id/iv2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:visibility="invisible" /> <ImageButton android:id="@+id/menu_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_toRightOf="@+id/BunyiIng" android:src="@drawable/menu_btn" android:background="@null" /> <ImageView android:id="@+id/image_logo" android:src="@drawable/logo_vehicle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:layout_marginTop="5px" /> </RelativeLayout> </LinearLayout> 

If I put ImageViews in LinearLayout, it blocked RelativeLayout.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout1" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingBottom="10px" android:paddingLeft="10px" > <ImageView android:id="@+id/iv1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:visibility="invisible" /> <ImageView android:id="@+id/iv2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:visibility="invisible" /> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" > 

But if the Imageview is below the RelativeLayout but inside the LinearLayout, the ImageView does not show the image.

  </RelativeLayout> <ImageView android:id="@+id/iv1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:visibility="invisible" /> <ImageView android:id="@+id/iv2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:visibility="invisible" /> </LinearLayout> 

How do I solve it? I want the ImageView to display the image in full screen.

+6
source share
3 answers
  • You have a linear layout add-on.
  • You have nothing in the representation of the image to see its contents so that you cannot see its contents.
  • You set an invisible image so that you cannot see its contents.
  • If you are not interested in aspect ratio, use android: adjustViewBounds = "false" and android: scaleType = "fitXY".
+24
source

Use this property to view the image:

 android:scaleType="fitXY" 
+2
source

I see that the height and width of your ImageViews are equal to "fill_parent", so I assume that you want both of them to scale to full screen. If you want them to just sit and not intend to use them for anything later, add

 android:background="@drawable/your_drawable_here" 

for both your linear and relative layouts. It will add the image to the background of the layout, scale it to fit the whole layout, and save some resources if Iā€™m not mistaken.

0
source

Source: https://habr.com/ru/post/916337/


All Articles