简体   繁体   中英

Android. ImageView wrap in FrameLayout

I want imageView wrap in FrameLayout. And ImageView show fullscreen.

1 variant:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout       
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffff00" >

<FrameLayout
    android:id="@+id/fl_draw"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:background="#00ff00">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/vertical_test"
        android:adjustViewBounds="true" />

</FrameLayout>

</RelativeLayout>

VAR1
(source: cs412821.vk.me )

2 variant:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout       
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffff00" >

<FrameLayout
    android:id="@+id/fl_draw"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:background="#00ff00">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/vertical_test"
        android:adjustViewBounds="true" />

</FrameLayout>

</RelativeLayout>

VAR2
(source: cs412821.vk.me )

AdjustViewBounds not working.

What I'm trying to achieve:

VAR1
(source: cs412821.vk.me )

How do I handle this? Thank you very much. Sorry for my english.

Change your imageview attributes from :

<ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/vertical_test"
        android:adjustViewBounds="true" />

To:

<ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/vertical_test"
        android:adjustViewBounds="true" />

It also depends on how tall your image is.. If you know the width and height, you can adjust it accordingly.

Also, you can use gravity attribute if you want the want the image to be in the center position.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM