TextView ellipsize在RelativeLayout中不起作用

时间:2013-12-05 15:16:07

标签: android android-layout 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="65dp"
    android:background="@drawable/dash_whiteplate"
    android:minHeight="@dimen/info_activity_list_item_height"
    android:orientation="vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:weightSum="1.0" >

    <RelativeLayout style="@style/ItemFlightRouteLayout" >

        <ImageView
            android:id="@+id/routImageTop"
            style="@style/ItemFlightRouteArrow"
            android:src="@drawable/icon_arrowup_normal" />

        <TextView
            android:id="@+id/routAiroportFrom"
            style="@style/ItemFlightRouteAirportName"
            android:layout_toLeftOf="@+id/topDescription"
            android:layout_toRightOf="@+id/routImageTop"
            android:textAppearance="@style/ItemFlightRouteAirportName"
            android:text="askdjflsfksdfasdfdfsfdsfsdfsfdsdfsfd" />

        <RelativeLayout
            android:id="@+id/topDescription"
            style="@style/ItemFlightRouteDescriptionLayout" >

            <View
                android:id="@+id/verticalDivider"
                style="@style/ItemFlightRouteSeparator"
                android:layout_toLeftOf="@+id/txt_time" />

            <RelativeLayout
                android:id="@+id/txt_time"
                android:layout_width="60dp"
                android:layout_height="match_parent"
                android:layout_toLeftOf="@+id/verticalDivider2" >

                <TextView
                    android:id="@+id/timeDep"
                    style="@style/ItemFlightRouteText"
                    android:textColor="@color/statusLanded" />
            </RelativeLayout>

            <View
                android:id="@+id/verticalDivider2"
                style="@style/ItemFlightRouteSeparator"
                android:layout_toLeftOf="@+id/txt_gate" />

            <RelativeLayout
                android:id="@+id/txt_gate"
                android:layout_width="60dp"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true" >

                <TextView
                    android:id="@+id/desciptionTop"
                    style="@style/ItemFlightRouteText" />
            </RelativeLayout>
        </RelativeLayout>
    </RelativeLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:background="@color/grey" />

    <RelativeLayout style="@style/ItemFlightRouteLayout" >

        <ImageView
            android:id="@+id/routImageBottom"
            style="@style/ItemFlightRouteArrow"
            android:src="@drawable/icon_arrowdown_normal" />

        <TextView
            android:id="@+id/routAiroportTo"
            style="@style/ItemFlightRouteAirportName"
            android:layout_toLeftOf="@+id/bottomDescription"
            android:layout_toRightOf="@+id/routImageBottom"
            android:textAppearance="@style/ItemFlightRouteAirportName" />

        <RelativeLayout
            android:id="@+id/bottomDescription"
            style="@style/ItemFlightRouteDescriptionLayout" >

            <View
                android:id="@+id/verticalDivider3"
                style="@style/ItemFlightRouteSeparator"
                android:layout_toLeftOf="@+id/txt_time2" />

            <RelativeLayout
                android:id="@+id/txt_time2"
                android:layout_width="60dp"
                android:layout_height="match_parent"
                android:layout_toLeftOf="@+id/verticalDivider4" >

                <TextView
                    android:id="@+id/timeArr"
                    style="@style/ItemFlightRouteText" />
            </RelativeLayout>

            <View
                android:id="@+id/verticalDivider4"
                style="@style/ItemFlightRouteSeparator"
                android:layout_toLeftOf="@+id/txt_gate2" />

            <RelativeLayout
                android:id="@+id/txt_gate2"
                android:layout_width="60dp"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true" >

                <TextView
                    android:id="@+id/desciptionBottom"
                    style="@style/ItemFlightRouteText" />
            </RelativeLayout>
        </RelativeLayout>
    </RelativeLayout>

</LinearLayout>

和样式:

<style name="ItemFlightRouteLayout">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_weight">0.5</item>
    <item name="android:weightSum">1.0</item>
</style>

<style name="ItemFlightRouteArrow">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_alignParentLeft">true</item>
    <item name="android:layout_centerInParent">true</item>
    <item name="android:layout_marginLeft">5dp</item>
</style>

<style name="ItemFlightRouteAirportName">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:layout_centerVertical">true</item>
    <item name="android:layout_margin">5dp</item>
    <item name="android:ellipsize">marquee</item>
    <item name="android:padding">2dp</item>
    <item name="android:singleLine">true</item>
    <item name="android:textColor">@android:color/black</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textSize">14sp</item>
</style>

<style name="ItemFlightRouteDescriptionLayout">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:layout_alignParentRight">true</item>
    <item name="android:layout_gravity">right</item>
</style>

<style name="ItemFlightRouteSeparator">
    <item name="android:layout_width">1dp</item>
    <item name="android:layout_height">22dp</item>
    <item name="android:layout_centerVertical">true</item>
    <item name="android:layout_marginBottom">5dp</item>
    <item name="android:layout_marginTop">5dp</item>
    <item name="android:background">@color/grey</item>
</style>

<style name="ItemFlightRouteText">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:layout_centerVertical">true</item>
    <item name="android:layout_margin">5dp</item>
    <item name="android:gravity">center</item>
</style>

enter image description here

3 个答案:

答案 0 :(得分:5)

最后我知道了! 我做了什么:将routImageTop和routAiroportFrom移动到LinearLayout,在父左侧对齐并设置android:layout_toLeftOf="@+id/topDescription"
现在它有效。

答案 1 :(得分:0)

添加你的Xml

<item name="android:marqueeRepeatLimit">marquee_forever</item>

在活动中

your_textview.setSelected(true);
your_textview.setSingleLine(true);
your_textview.setEllipsize(TruncateAt.MARQUEE);

我认为你也可以将这些值放在Xml中......

希望这个帮助

答案 2 :(得分:0)

TextView需要专注于在TextView中滚动选框。您是否尝试使用selected_state,requestFocus或setSelected将焦点设置为TextView?

Make a Scrolling Marquee, using scrollHorizontally, in a TextView

Deprecated: Make a Scrolling Marquee, using singleLine, in a TextView