1

What is the best way to accomplish textView scrolling inside listview when it doesn't fit and only when specific row inside listview is selected. 另外,我希望我的文本从左侧滚动到右侧,当它到达末尾时从右侧向后滚动到左侧(不像选框那样默认)

ListView 行的 XML:

<TextView
            android:id="@+id/txtWouldLikeToScroll"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:paddingBottom="1dp"
            android:textColor="#fff"
            android:textStyle="bold"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="true"  
            android:singleLine="true"
             />

我正在使用自定义 ListViewAdapter 并覆盖滚动侦听器:

myList.setOnScrollListener(new OnScrollListener() {

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem,
                    int visibleItemCount, int totalItemCount) {


                // TODO Auto-generated method stub

            }

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

                switch (scrollState) {
                case OnScrollListener.SCROLL_STATE_IDLE:

                  view.setSelection(positionWhereIwouldLikeToPointSelection);

                    break;
                case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
                    break;
                case OnScrollListener.SCROLL_STATE_FLING:
                    break;
                }

            }

        });

    }

我想我必须设置要选择的文本视图(我在 ListView 中设置选择的那个),并且不知道如何覆盖选取框行为。

谢谢

4

2 回答 2

1

尝试动画。它易于使用,并且完全符合您的要求:

<TextView
    android:id="@+id/textview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:maxLines="1" />

现在Java代码:

private TextView mTextView...
private Animation mAnimation...

private void animateTextView() {
    int textWidth = getTextViewWidth(mTextView);
    int maxWidth = ... // Do not know what width you want.

    /* Start animation only when text is longer than dislay width. */
    if(maxWidth<textWidth) {
        mAnimation = new TranslateAnimation(
                0, displayWidth-textWidth,
                0, 0);
        mAnimation.setDuration(3000);    // Set custom duration.
        mAnimation.setStartOffset(500);    // Set custom offset.
        mAnimation.setRepeatMode(Animation.REVERSE);    // This will animate text back ater it reaches end.
        mAnimation.setRepeatCount(Animation.INFINITE);    // Infinite animation.

        mTextView.startAnimation(mAnimation);
    }
}

private int getTextViewWidth(TextView textView) {
    textView.measure(0, 0);    // Need to set measure to (0, 0).
    return textView.getMeasuredWidth();
}
于 2013-08-07T16:54:04.193 回答
0

你可以这样做。

xml 为TextView

<TextView
    android:id="@+id/label"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:singleLine="true" />

我假设您正在扩展您的活动ListActivity。在您的onListItemClick

public void onListItemClick(ListView parent, View row, int position, long id) {

    TextView textViewOne =   (TextView)row.findViewById(R.id.text_view);
    textViewOne.setSelected(true);
    for (int i = 0; i < parent.getChildCount(); i++) {
        if(i!=position){
            View view = (View) parent.getChildAt(i).findViewById(R.id.view);

            textViewOne = (TextView)view.findViewById(R.id.text_view);
            textViewOne.setSelected(false);

        }
    }   
}
于 2013-02-21T12:59:17.360 回答