Android:LinearView左右固定大小的小部件,中间是灵活的小部件

jan*_*ver 3 android android-linearlayout

似乎是一个简单的问题,但我无法弄清楚如何做到这一点.

我有一个水平的LinearView,在左边有一些固定大小的东西,然后是一些文本应该尽可能地作为mich空间,但在右边应该是另一个固定大小的对象.

现在,我的问题是现在:当中间的文本太长时,右边的对象被推出窗口.当文本太短时,它不会位于窗口的右边界,而是直接位于文本旁边.

我该怎么做?到目前为止我的代码(正如你所看到的,我试图使用LayoutWeight,这没有帮助......):

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

    <TextView
        android:id="@+id/important"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="10dp"
        android:background="#000000"
        android:layout_weight="1"/>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1">
        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="5dp"
            android:paddingRight="5dp"
            android:paddingLeft="0dp"
            android:textColor="#333333"
            android:paddingBottom="0dp"
            android:textSize="14sp"
            android:scrollHorizontally="true"/>
        <TextView
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#666666"
            android:paddingTop="3dp"
            android:paddingRight="5dp"
            android:paddingLeft="10dp"
            android:paddingBottom="5dp"
            android:textSize="12sp" />
    </LinearLayout>

    <ImageView android:id="@+id/lastpage" 
        android:src="@drawable/lastpage"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="200"
        android:scaleType="center"
        android:layout_gravity="right"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Com*_*are 7

你有android:layout_weight="1"两个小部件(第一个和第二个孩子LinearLayout),这与你的业务规则不符.

就个人而言,我会在RelativeLayout这里使用.使用android:layout_alignParentLeft="true"的第一个孩子,android:layout_alignParentRight="true"在第三个孩子,并android:toLeftOfandroid:toRightOf在中间,外固定子女之间固定好.这更明确地实现了您期望的业务规则.


sun*_*rer 6

看看这个答案Android:LinearView左右固定大小的小部件和中间的灵活小部件你可能只需要将layout_width你的中间元素设置为0px,使其不使用内容获得的宽度,而是通过重量.

希望这可以帮助.