gpt4 book ai didi

android - 带选取框的 TextView 无法正常工作

转载 作者:太空狗 更新时间:2023-10-29 14:14:16 25 4
gpt4 key购买 nike

尽管我按照教程制作了一个 marquee TextView,并且它工作正常,但当我尝试在不同的 Activity 中制作另一个 TextView 作为 marquee 它没有用。我准确地按照相同的步骤进行,但无济于事。你认为我缺少什么?

更新

我认为问题出在 View 的 focus 上,因为我已经测试过即使在调用 imgPathTv.setSelected(true) 之后 TextView 是否有焦点,结果没有焦点。

Updated_Code

String imgPath = dataBaseRow.getImgPath();
if (imgPath.equals("")) {
Log.d(TAG, "@createInfoReport(): dataBaseRow.getImgPath() Returns NULL");
imgPathTv.setText("NULL");
}else {
Log.d(TAG, "@createInfoReport(): dataBaseRow.getImgPath() Has Value");

imgPathTv.setSelected(true);
imgPathTv.setText(imgPath);

if(imgPathTv.findFocus() != null) {
Toast.makeText(getApplicationContext(), "there is a View has the Focus", Toast.LENGTH_SHORT).show();
}else
Toast.makeText(getApplicationContext(), "NO View has the Focus", Toast.LENGTH_SHORT).show();
}

Java_代码:

    TextView imgPathTv = (TextView) mDialog.findViewById(R.id.imgPathValue);
Log.i(TAG, "@createInfoReport(): imgPathTv IS IN FOCUS");
imgPathTv.setSelected(true);

TextView_xml:

<TextView 
android:id="@+id/imgPathValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:fadingEdge="horizontal"/>

最佳答案

也许您的文本长度不够长,无法让跑马灯运行。换句话说,选取框仅在文本大于其各自的宽度/区域时才起作用。因此,我建议尝试将 android:layout_width 设置为,例如,200dp 或更多。然后试试 marquee。希望对您有所帮助。

关于android - 带选取框的 TextView 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24165143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com