简体   繁体   English

具有textview和按钮对齐的线性布局

[英]Linear layout with textview and button alignment

I am trying hard time to align this paticular layout but unable to set it correctly. 我正在努力对齐此特殊布局,但无法正确设置它。

can anyone help me out with this. 谁能帮我这个忙。

I need exactly the row layout as shown below: 我确实需要如下所示的行布局:

在此处输入图片说明

This is what I have now: 这就是我现在所拥有的:

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/txtTitle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_weight="1"
            android:ellipsize="marquee"
            android:gravity="center_vertical"
            android:singleLine="true"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/txtadd"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="25dip"
            android:layout_weight="1"
            android:ellipsize="marquee"
            android:singleLine="true"
            android:textSize="18sp" />
    </LinearLayout>

    <TextView
        android:id="@+id/txtLongDesc"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:gravity="center_vertical"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:textColor="@color/blue_header"
        android:textSize="16sp" />
</LinearLayout>

<ImageView
    android:id="@+id/btndelete"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_gravity="right"
    android:layout_toRightOf="@+id/txtadd"
    android:layout_weight="1"
    android:scaleType="fitEnd"
    android:src="@drawable/ic_menu_delete" />

I want the button to be centered for both the linear layoyuts and the long text should be marquee. 我希望将按钮放置在线性layoyuts的中心,并且长文本应选框。 The problem is If I set the long textview to fill_parent its pushing the button. 问题是如果我将长fill_parent设置为fill_parent按下按钮。

Use LinearLayout with weight properties : LinearLayoutweight属性一起使用:

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

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/txtTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="marquee"
                android:gravity="center_vertical"
                android:singleLine="true"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/txtadd"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="marquee"
                android:singleLine="true"
                android:textSize="18sp" />
        </LinearLayout>

        <TextView
            android:id="@+id/txtLongDesc"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:gravity="center_vertical"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:textColor="@color/blue_header"
            android:textSize="16sp" />

    </LinearLayout>

    <ImageView
        android:id="@+id/btndelete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_menu_delete" />
</LinearLayout>

You can use this 你可以用这个

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

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.80"
        android:orientation="vertical" >

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/txtTitle"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ellipsize="marquee"
                android:gravity="center_vertical"
                android:singleLine="true"
                android:text="Lorem ipsum"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/txtadd"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ellipsize="marquee"
                android:singleLine="true"
                android:text="Lorem ipsum"
                android:textSize="18sp" />
        </TableRow>

        <TextView
            android:id="@+id/txtLongDesc"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:gravity="center_vertical"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit"
            android:textSize="16sp" />
    </LinearLayout>

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

</LinearLayout>

I hope this will help you. 我希望这能帮到您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM