简体   繁体   中英

Android ImageView getting over linearlayout

I'm developing an android application, The layout is shown in the image below :

Screenshot http://www.lebanon-trading-center.com/daymanager/layout.PNG

The layout contains 2 main linearlayouts : a horizontal layout that takes 90% of the height of the device and a vertical layout that takes 10% of it. Inside the horizontal linearlayout there is three linearlayout ( two red and one containing an imageview). Each red layout is 10% of the width of the screen and the one containing the ImageView is 80%. Here is the xml code :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_weight="0.9"
        android:weightSum="1"
         >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_weight="0.1"
            android:background="#ff0000" >
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:gravity="center_horizontal"
            android:layout_weight="0.8" >

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

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_weight="0.1"
            android:background="#ff0000"  >
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="0.1"
        android:background="#000000" >
    </LinearLayout>

</LinearLayout>

The problem is, when I set a PNG image (1036px X 730px ) as a source to the ImageView, the ImageView will get over the bottom linearlayout ( the black one ) and the two red layouts will be squeezed.

Screenshot http://www.lebanon-trading-center.com/daymanager/layout2.PNG

My question is how can I solve the problem and have the same layouts functional on all kind of tablets ?

Try this way,hope this will help you to solve your problem.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        android:layout_weight="0.90">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_weight="0.10"
            android:background="#ff0000" >
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:gravity="center_horizontal"
            android:layout_weight="0.80" >

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY"
                android:src="@drawable/ic_launcher" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_weight="0.10"
            android:background="#ff0000"  >
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="vertical"
        android:layout_weight="0.10"
        android:background="#000000" >
    </LinearLayout>

</LinearLayout>

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