我有一个Gridveiew。在我传递的GridView的getView中,有一个RelativeLayout(包含图像视图和textview作为它的子节点)。我希望textview的文本水平滚动,因为它太长了。 这是我的xml。但是textview不会滚动
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false">
<ImageView
android:id="@+id/theme_preview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY" />
<TextView
android:id="@+id/theme_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/theme_preview"
android:layout_centerHorizontal="true"
android:lines="1"
android:ellipsize="marquee"
android:scrollHorizontally="true"
android:marqueeRepeatLimit="marquee_forever"
/>
</RelativeLayout>
答案 0 :(得分:2)
android:scrollHorizontally="true"
或者,如果您想在代码中执行此操作:
textView.setHorizontallyScrolling(true);
答案 1 :(得分:0)
Try Using this,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false">
<ImageView
android:id="@+id/theme_preview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY" />
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/theme_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/theme_preview"
android:layout_centerHorizontal="true"
android:lines="1"
android:ellipsize="marquee"
android:scrollHorizontally="true"
android:marqueeRepeatLimit="marquee_forever"
/>
</HorizontalScrollView>
</RelativeLayout>
答案 2 :(得分:0)
尝试使用此,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="70dp"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center_vertical|center_horizontal"
android:layout_marginTop="14dp"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/item_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/item_image"
android:layout_below="@+id/item_image"
android:scrollHorizontally="true"
android:singleLine="true"
android:freezesText="false"
android:selectAllOnFocus="false"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:gravity="center_vertical|center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
在GridView适配器类中设置textview.setSelected(true)
holder.txtTitle = (TextView) row.findViewById(R.id.item_text);
holder.txtTitle.setSelected(true);