java - Android ImageView 克服线性布局

标签 java android android-layout

我正在开发一个android应用程序,布局如下图所示:

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

布局包含 2 个主要的线性布局:水平布局占设备高度的 90%,垂直布局占设备高度的 10%。水平线性布局内部有三个线性布局(两个红色,一个包含 ImageView )。每个红色布局占屏幕宽度的 10%,包含 ImageView 的占屏幕宽度的 80%。这是 xml 代码:

<?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>

问题是,当我将 PNG 图像(1036px X 730px)设置为 ImageView 的源时,ImageView 将越过底部的线性布局(黑色的),并且两个红色布局将被挤压。

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

我的问题是如何解决该问题并在所有类型的平板电脑上使用相同的布局?

最佳答案

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>

关于java - Android ImageView 克服线性布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24320783/

相关文章:

java - 如何使用 "Out.Format(Format,String Var)"错误 "The method format(String, String) is undefined for the type JspWrite"在 JSP 页面格式化字符串?

java - Android 优点 : How to wrap PayPal's MPL?

java - 使用 Android 发送 HTTP Post 请求

android - Android 中 getTextView 的 NullPointerException

android - 相对布局中的ImageView和listview

android - NestedScrollView 中的 ViewPager

java - 有什么方法可以将 Constants 类中的 Java 常量转换为另一个类中的迭代形式吗?

java - Java 找不到符号错误

java - 测试用例使此代码失败?

android - 在 2 个不同的 Activity 上显示一个对话框