I want to create a LinearLayout with two TextViews: a label and a data placeholder. Since the data can be arbitrarily long, I want to restrict the size of the second TextView to a single line, and to automatically scroll horizontally if the data does not fit in the view.
Also, I want the width of the second TextView to be calculated at runtime, so that it can fill 70% of the parent container and be aligned to its right.
So far this is what I've got:
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/ll_denunciante" > <TextView android:id="@+id/txtv_label_denunciante" android:layout_width="0px" android:layout_height="wrap_content" android:layout_weight="0.3" android:gravity="left" android:text="@string/txtv_label_denunciante" /> <TextView android:id="@+id/txtv_data_denunciante" android:layout_width="0px" android:layout_height="wrap_content" android:layout_weight="0.7" android:gravity="right" android:maxLines="1" android:ellipsize="marquee" android:scrollHorizontally="true" android:marqueeRepeatLimit="marquee_forever" android:text="@string/txtv_no_data" /> </LinearLayout> But the text is simply cut off. It is not ellipsized and automatic scrolling does not work. Adding
android:focusable="true" android:focusableInTouchMode="true" does not fix the problem.
The answer to this question did not help either.
I'll gladly accept an answer using a RelativeLayout if it accomplishes the desired result using less code or if it is not possible using a LinearLayout.
Edit
Changing the second TextView to:
<TextView android:id="@+id/txtv_data_denunciante" android:layout_width="0px" android:layout_height="wrap_content" android:layout_weight="0.7" android:ellipsize="marquee" android:gravity="right" android:marqueeRepeatLimit="marquee_forever" android:singleLine="true" android:text="@string/txtv_no_data" /> and adding
txtvDataDenunciante.setSelected(true); fixed it.