我有一个textView,其大小为16个字符,如果超过16个字符,我想让它可以滚动到用户查看剩余的字符.任何人都可以帮助我吗?
我试过这个链接让TextView可以在Android上滚动
但没有结果?
我的TextView布局:
<TextView
android:id="@+id/tv1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:maxLength="16"
android:scrollbars = "vertical"
android:ellipsize="end"
android:text="fdgdddhhhdhd"
/>
Run Code Online (Sandbox Code Playgroud) 我想创建一个带有可滚动文本视图的 Android 小部件。
对于这个问题 Making TextView可滚动的Android的解决方案 不能应用,因为它是一个小部件:
1.这个
findViewById(R.id.textview).setMovementMethod(new MovementMethod());
Run Code Online (Sandbox Code Playgroud)
不起作用,因为findViewById在 中不可用,AppWidgetProvider而仅在 中可用Activity。
2.ScrollView放置aTextView也不起作用,因为我得到一个
InflateException:
android.view.InflateException: Binary XML file line #23: Error inflating class ScrollView
Run Code Online (Sandbox Code Playgroud)
有人可以给我一个提示,如何使TextViewWidget 中的 可以滚动吗?
android textview android-widget scrollable android-appwidget
我想让我的 TextView 垂直滚动。我读过“在Android中使TextView可滚动”,但由于我不知道最终设备的屏幕尺寸,所以我不知道应该为最大行数设置哪个值。
还有其他方法可以实现任何屏幕尺寸的滚动吗?
我的 XML 看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_weight="1.0">
<TextView
android:id="@+id/consola"
android:layout_width="fill_parent"
android:layout_height="match_parent"/>
</ScrollView>
<EditText
android:id="@+id/comando"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.0"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.0">
<Button
android:text="Conectar"
android:id="@+id/boton_conectar"
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_height="wrap_content">
</Button>
<Button
android:text="Enviar"
android:id="@+id/boton_enviar"
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 实际上我在textview中显示一些数据,但它的一半数据已经出现在屏幕上,所以我需要帮助来制作textview滚动或任何其他可以向下滚动屏幕的东西.
任何帮助,将不胜感激!
我在活动中创建了片段。每个片段都有一个文本视图。我想让片段内的所有文本视图都可以滚动。下面是我的 xml 和 java 代码。提前致谢
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".chemistry.AtomicNumber">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/atomicNumberDefinition"
android:text="The atomic number..... "
android:textAlignment="center"
android:textColor="#000000"
android:textSize="24sp"
android:scrollbars="vertical" />
Run Code Online (Sandbox Code Playgroud)
Java代码:
public class AtomicNumber extends Fragment {
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private String mParam1;
private String mParam2;
public AtomicNumber() {
}
public static AtomicNumber newInstance(String param1, String param2) {
AtomicNumber fragment = new AtomicNumber();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args); …Run Code Online (Sandbox Code Playgroud) 如何在我的应用程序中平滑滚动文本视图?这是一个类似于我的 main.xml 的示例:
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="ANDROID APPLICATION INFO"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FF8000"
tools:ignore="HardcodedText" />
<RadioButton
android:id="@+id/radio_english"
android:layout_width="201dp"
android:layout_height="55dp"
android:onClick="onRadioButtonClicked"
android:text="English"
tools:ignore="HardcodedText" />
<RadioButton
android:id="@+id/radio_it"
android:layout_width="200dp"
android:layout_height="55dp"
android:onClick="onRadioButtonClicked"
android:text="Ita"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/AndroidInfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Android Info.:"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/Ainfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
tools:ignore="SelectableText"
android:text="blablablablabla blablablabla blablablablabla blablablabla `blablablablabla blablablabla blablablablabla blablablabla blablablablabla blablablabla" />`
</RadioGroup>
Run Code Online (Sandbox Code Playgroud)
Ainfo textview 是我想让它滚动的。但滚动流畅。我尝试了不同的方法,但我尝试的一切都导致滚动不顺畅。有什么技巧可以做吗?不要考虑功能,因为是一个例子..只是想了解如何使滚动平滑。
我正在开发1个应用程序,因为我需要1 scrollview在这个scrollview中我需要放置scrolling textview/ webview(必须显示一些静态字符串)但必须在scrollview内滚动但不能正常工作
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/img_view_flag"
android:layout_marginTop="17dp"
android:paddingBottom="20dip">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/rel_layout"
android:layout_marginTop="15dp"
android:maxLines="2"
android:scrollbars="vertical"
android:text="Medium Text"
android:paddingBottom="10dip"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
在myjava文件中我做了...
scrollView1 = (ScrollView) findViewById(R.id.scrollView1);
// scrollView2 = (ScrollView) findViewById(R.id.scrollView2);
tv = (TextView) findViewById(R.id.tv_desc);
tv.setText("this is 1\n"+"this is 2"+"\n this ix 3\n"+"this is 4\n\n"+"this is 5\n" );
scrollView1.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent …Run Code Online (Sandbox Code Playgroud) 我已经搜索并搜索找到如何将垂直(或水平)滚动条添加到 TextView 而不必使用 XML 来添加行的答案:android:scrollbars="vertical"。
必须有一种方法可以以编程方式执行此操作,而无需将其粘贴在另一个 ScrollView 中。
我刚刚发现如何以及因为我对此感到兴奋并想帮助其他遇到相同问题的人,这里是: