【问题标题】:Android Marquee in TextView truncated and scrolls only in landscapeTextView中的Android Marquee被截断并且仅在横向滚动
【发布时间】:2016-01-09 12:28:27
【问题描述】:

我面临以下两个相关的 (?) 问题:

  1. 虽然文本在横向模式下自动滚动,但它 在纵向模式下根本不滚动。
  2. 横向模式下的文本 即滚动是椭圆形和截断的。我希望 滚动文本以显示其余文本。

请注意,我正在构建一个 AlertDialog。下面是代码:

public class AboutFragment extends DialogFragment
{
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState)
    {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

        String message = "Top line message";

        builder.setTitle(R.string.about_title);
        View v = this.getActivity().getLayoutInflater().inflate(R.layout.about_scrollable,null);
        TextView tv = (TextView) v.findViewById(R.id.about_txt_scr);
        TextView tv2 = (TextView) v.findViewById(R.id.about_message);
        tv2.setText(message);
        tv.setSelected(true);
        tv.setEllipsize(TextUtils.TruncateAt.MARQUEE);
        tv.requestFocus();
        builder.setView(v);


        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id)
            {
                //nothing really to be done here
            }
        });

        return builder.create();
    }
}

还有布局:

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

    <TextView
        android:id="@+id/about_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="20dp"
        android:paddingBottom="0dp"
        />
    <TextView  
        android:id="@+id/about_txt_scr"
        android:text="A really long text that is going on and on but it actually truncated using ellipsis in this example"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="0dp"
        android:paddingBottom="20dp"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:textIsSelectable="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:lines="1"/>

</LinearLayout>

【问题讨论】:

    标签: android textview android-alertdialog ellipsis


    【解决方案1】:

    为您的文本视图“about_txt_scr”尝试以下属性

    <TextView
            android:id="@+id/about_txt_scr"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:freezesText="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:paddingLeft="15dip"
            android:paddingRight="15dip"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:text="A really long text that is going on and on but it actually truncated using ellipsis in this example" />
    

    并从 onCreateDialog 方法中注释这 2 行

     //tv.setEllipsize(TextUtils.TruncateAt.MARQUEE);
     //tv.requestFocus();
    

    【讨论】:

    • 这是正确的。谢谢。事实上,造成差异的行是删除 android:textIsSelectable 和 2 个 java 行
    猜你喜欢
    • 2012-10-04
    • 1970-01-01
    • 1970-01-01
    • 2017-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多