我正在做一个应用程序,其中 LinearLayout 中有一个 TextView 和一个 ImageView 。触摸线性布局会将我们带到另一项 Activity 。由于文本不适合 TextView ,我想使 TextView 内容选取框。我已经尝试了很多方法,但它不起作用。 xml内容如下。
<LinearLayout
android:id="@+id/profile_pic_Layout"
android:layout_width="fill_parent"
android:layout_height="100dip"
android:layout_margin="10dip"
android:background="@color/blue_background" >
<ImageView
android:id="@+id/profile_pic_menu"
android:layout_width="100dip"
android:layout_height="100dip"
android:contentDescription="@string/image"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/profile_name_text"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:layout_gravity="bottom"
android:gravity="center"
android:marqueeRepeatLimit="1"
android:inputType="text"
android:lines="1"
android:duplicateParentState="true"
android:scrollHorizontally="true"
android:fadingEdge="horizontal"
android:focusable="true"
android:textColor="@android:color/white"
android:textSize="20sp">
<requestFocus android:focusable="true"
android:focusableInTouchMode="true"
android:duplicateParentState="true" />
</TextView>
</LinearLayout>
我还尝试使用设置在代码中选择的 TextView ,
profileNameTextView.setEllipsize(TruncateAt.MARQUEE);
profileNameTextView.setSelected(true);
我认为这是因为父线性布局具有焦点。 请帮我解决这个问题..!
提前谢谢大家..!
最佳答案
显然您缺少 android:ellipsize="marquee"
属性
这是一个简约的工作示例:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:marqueeRepeatLimit="1"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="HELLO HOW ARE YOU WHAT ARE YOU DOING TEST ANDROID IS WRITING TO YOU." />
关于android - 如何在android中的集中布局内制作textview选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12110696/