0

thank you for your time.

I have a list of Strings that a display inside a gridview using an ArrayAdapter. Some of those Strings are long and take too much room. I want to limit the height of each grid cell to 1 line and be able to read the full string when i'm clicking on this cell.

Here's my gridview.xml :

    <GridView
    android:id="@+id/songSelectionGrid_grid"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@id/songSelectionGrid_button_back"
    android:columnWidth="90sp"
    android:horizontalSpacing="10dp"
    android:numColumns="3"
    android:verticalSpacing="10dp" />

and here is my textview inside my gridview :

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItemSmall" 
android:maxLines = "1"
android:scrollbars = "horizontal"/>

How can i make the Strings scroll horizontally ? I've tried a onItemClickListener on the gridview followed by a "setMovementMethod" on the view, but it need to be a TextView and casting it doesn't seem to work

Thanks !

4

1 回答 1

0

好的,所以我设法让它按预期工作:gridview 显示多个专辑(封面图片+水平滚动文本)。为此,我使用以下 getView() 创建了自己的 GridAdapter :

    public View getView(int position, View convertView, ViewGroup parent)
{
    // TODO Auto-generated method stub
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View gridView = null;
    convertView = null;
    if(convertView == null)
    {
        gridView = new View(context);
        gridView = inflater.inflate(R.layout.gridtextview, null);
        TextView textView = (TextView) gridView.findViewById(R.id.gridView_text);

        textView.setText(textArray[position]);
        Log.i("GridAdapter","textView.getText : 
    }
    return gridView;
}

我正在填充的 gridView 由以下内容组成:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridView_topLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >

<ImageView
    android:id="@+id/gridView_image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:contentDescription="@string/gridTextView_Album"
    android:src="@drawable/ic_launcher" />

<HorizontalScrollView
    android:id="@+id/gridView_horizontalScroll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="left"
    android:clipChildren="true"
    android:fillViewport="true"
    android:scrollbars="none" >

    <RelativeLayout
        android:id="@+id/gridView_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/gridView_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:isScrollContainer="true"
            android:paddingBottom="10sp"
            android:singleLine="true" />
    </RelativeLayout>
</HorizontalScrollView>

我不确定这是最好的方法,但它确实有效。但是,请记住,我仍然是 android dev 的初学者 :)

于 2013-06-17T08:54:09.070 回答