2

我在设计应用程序布局时遇到问题。这就是我想要得到的:

=========================================================
|  =============   ================   ================  |
|  |           |   | LinearLayout |   | LinearLayout |  |
|  |           |   | ============ |   | ============ |  |
|  |           |   | | TextView | |   | | TextView | |  |
|  | ImageView |   | ============ |   | ============ |  |
|  |           |   | ============ |   | ============ |  |
|  |           |   | | TextView | |   | | TextView | |  |
|  |           |   | ============ |   | ============ |  |
|  |           |   | ============ |   | ============ |  |
|  |           |   | | TextView | |   | | TextView | |  |
|  |           |   | ============ |   | ============ |  |
|  =============   ================   ================  |
=========================================================

这就是我到目前为止所做的事情(为了清楚起见,我删除了另一个东西):

<?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="wrap_content"
    android:orientation="horizontal"
    android:gravity="center_vertical" >


    <ImageView
        android:contentDescription="@string/logo"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="left|center_vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="right|center_vertical"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true" />

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true" />

    </LinearLayout>

</LinearLayout>

我的问题是我想使用高分辨率图像并将它们缩小以匹配它旁边的最高线性布局。我的想法是让 android 在低 dpi 的设备上缩小图像,因此对所有平台使用相同的图像和布局。

就像现在一样,主容器高度与图像高度一样大。我想要的是主容器高度与“最高”线性布局相同,并强制图像视图按比例缩小以适合主容器。

有任何想法吗?

谢谢!

PD:原谅我的英语!:$

4

3 回答 3

1

所有视图的高度宽度和所有这些东西都是在活动的 onMeasure() 中测量的。值得注意的一点是,任何视图的 onMeasure() 都在 onDraw() 之前执行,并且可以执行 n 次. 因此,最好在其 onMeasure() 中计算 LinearLayout 的宽度和高度。

于 2013-07-23T05:46:30.873 回答
0
    LinearLayout ll = (LinearLayout)findViewById(R.id.your_linearlayout);

    int llHeight = ll.getHeight();

    ImageView iv = (ImageView)findViewById(R.id.your_imageview);

    LayoutParams ivParams = ((ImageView)findViewById(R.id.your_imageview)).getLayoutParams();

    ivParams.height = llHeight;

    iv.setLayoutParams(ivParams );
于 2013-07-23T04:32:51.020 回答
0

尝试实现以下代码。

见下图。

这是以下代码的屏幕截图

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="horizontal"
          android:layout_width="match_parent"
          android:weightSum="1"
          android:background="#FFFFFF"
          android:layout_height="match_parent">

<LinearLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:background="#000000"
        android:layout_marginTop="15dp"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:weightSum="5"
        android:orientation="horizontal">

    <ImageView
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:layout_weight="0.9"
            android:background="@drawable/black"/>

    <LinearLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:layout_weight="1.15">
    </LinearLayout>
    <LinearLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:layout_weight="0.9"
            android:weightSum="4"
            android:orientation="vertical">

        <TextView
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:layout_weight="1"
                android:text="Linear Layout"
                android:gravity="center_vertical|center_horizontal"
                android:textSize="25dp"/>
        <TextView
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:layout_weight="1"
                android:text="TextView"
                android:gravity="center_vertical|center_horizontal"
                android:textSize="25dp"/>
        <TextView
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:layout_weight="1"
                android:text="TextView"
                android:gravity="center_vertical|center_horizontal"
                android:textSize="25dp"/>
        <TextView
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:layout_weight="1"
                android:text="TextView"
                android:gravity="center_vertical|center_horizontal"
                android:textSize="25dp"/>
    </LinearLayout>

<LinearLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:layout_weight="1.15">
    </LinearLayout>
    <LinearLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:layout_weight="0.9"
            android:weightSum="4"
            android:orientation="vertical">
        <TextView
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:layout_weight="1"
                android:text="Linear Layout"
                android:gravity="center_vertical|center_horizontal"
                android:textSize="25dp"/>
        <TextView
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:layout_weight="1"
                android:text="TextView"
                android:gravity="center_vertical|center_horizontal"
                android:textSize="25dp"/>
        <TextView
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:layout_weight="1"
                android:text="TextView"
                android:gravity="center_vertical|center_horizontal"
                android:textSize="25dp"/>
        <TextView
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:layout_weight="1"
                android:text="TextView"
                android:gravity="center_vertical|center_horizontal"
                android:textSize="25dp"/>
    </LinearLayout>
</LinearLayout>

于 2013-07-23T05:38:26.640 回答