G
G
grabbee2016-12-07 12:11:03
Android
grabbee, 2016-12-07 12:11:03

How to solve glitch with TextView in markup?

I'm trying to fit the text of the incoming message in one line. The text can exceed the block width for it. Then I wanted to implement a behavior in which the text ends at the border of the block with a "fading" - gradually disappearing. Found this recipe:

android:fadingEdge="horizontal"
android:ellipsize="none"
android:maxLines="1"
android:fadingEdgeLength="150dp"
android:requiresFadingEdge="horizontal"
android:inputType="text"

Glitch next. If you do not specify android:inputType="text" then no fading occurs, the text is simply cut off. I do onClick on the parent layout. Then the click stabats on any nested element in the layout. But, if you specify android:inputType="text" - the fading works perfectly, but clicking on the TextView element, as if nested, stops working. Other nested elements continue to be "clicked". What's happening?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/search_item"
    android:paddingBottom="15dp"
    android:paddingTop="15dp"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:clickable="true"
    android:orientation="vertical">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:id="@+id/user_data"
        android:gravity="center_vertical"
        android:elevation="0dp"
        android:layout_alignParentLeft="true">

        <TextView
            android:text="Username"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/user_name"
            android:paddingRight="5dp"
            android:textSize="16sp"
            android:textColor="@android:color/black" />

        <TextView
            android:text="Привет. Как дела? Чем занимаешься? Как настроение? "
            android:layout_height="wrap_content"
            android:id="@+id/user_message"
            android:textSize="12sp"
            android:textColor="@color/text_gray"
            android:fadingEdge="horizontal"
            android:ellipsize="none"
            android:maxLines="1"
            android:fadingEdgeLength="150dp"
            android:requiresFadingEdge="horizontal"
            android:inputType="text"
            android:layout_weight="1"
            android:layout_width="0dp" />

        <ImageView
            android:layout_width="31dp"
            android:layout_height="wrap_content"
            app:srcCompat="@android:drawable/btn_star"
            android:id="@+id/user_favorite"
            android:layout_alignParentRight="true"
            android:layout_alignParentLeft="false"
            android:layout_weight="0" />

    </LinearLayout>

</LinearLayout>

The click is placed on "id/search_item"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
coden55, 2016-12-08
@coden55

Try rewriting one method for LinearLayout like this:

public boolean onInterceptTouchEvent (MotionEvent ev){
    return true;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question