【问题标题】:Android Two layout with fixed width in the sides and one layout with fluid widht in the middleAndroid 两种布局,两侧固定宽度,一种中间宽度可变的布局
【发布时间】:2015-02-06 10:59:24
【问题描述】:

我需要使列表视图的一行如下: 该行由三列组成,左侧必须包含背景颜色和中间文本的布局,右侧相同但带有图像。中间布局将包含三行文本 我需要两侧布局具有固定宽度,中间布局具有取决于设备分辨率的宽度。

示例:https://www.dropbox.com/s/udn1lfo1hy6px44/Captura%20de%20pantalla%202015-02-06%20a%20las%201.png?dl=0

我的代码:

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

    <RelativeLayout
        android:id="@+id/lytVoterNumber"
        android:layout_width="75dp"
        android:layout_height="match_parent"
        android:background="@android:color/holo_red_dark"
        android:layout_alignParentLeft="true">

        <TextView
            android:id="@+id/lblVoterNumber"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="1999"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            />
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/lytVoterData"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_toEndOf="@+id/lytVoterNumber"
        android:layout_toRightOf="@+id/lytVoterNumber">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Text Text Text"
            android:id="@+id/lblVoterLastName" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Text Text Text"
            android:id="@+id/lblVoterName" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Text Text Text"
            android:id="@+id/lblDni" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="100dp"
        android:layout_height="match_parent"
        android:background="@android:color/holo_blue_dark"
        android:id="@+id/lytIcono"
        android:layout_alignParentRight="true"
        android:minHeight="30dp"
        android:minWidth="30dp"
        android:nestedScrollingEnabled="false">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageView"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:src="@drawable/flecha"/>
    </RelativeLayout>
</RelativeLayout>

【问题讨论】:

  • 那么,你遇到了什么问题?
  • 是的,它有效!谢谢!。

标签: android android-layout layout


【解决方案1】:

检查一下

<LinearLayout  
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="10" >

这是一个 LinearLayoutorientation 水平,它有一个 10weight sum 现在你所要做的就是拆分 10 变为 3 并使两侧Views 具有相同的 10 比例,其余的将是中间人的比例,例如,如果你想要一个TextView 作为这个linearLayout 的孩子,给TextView 一个0dpwidth 和一个1 的weight,同样适用于另一个权利View,相同weight 相同width 然后剩下8/10,所以屏幕尺寸的8/10 是给你中间的View

所以你的整体看起来像这样

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="10" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:src="@drawable/ic_launcher" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="8"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:src="@drawable/ic_launcher" />

明白了吗,先生?

【讨论】:

  • 酷,这正是我需要的。核心是“weightSum”和“layout_weightSum”。谢谢
猜你喜欢
  • 1970-01-01
  • 2013-03-10
  • 2013-07-14
  • 2023-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-22
  • 1970-01-01
相关资源
最近更新 更多