【问题标题】:In edittext hint need to scroll horizontally在edittext提示需要水平滚动
【发布时间】:2016-07-27 06:24:59
【问题描述】:

在我的应用程序中,我有固定大小的编辑文本,但提示大小大于编辑文本,因此提示没有完全显示。我想通过水平滚动来完全显示提示,但我不知道如何做到这一点。

如果减小提示字体的大小会有所帮助,但我不想减小字体大小。

以下是我使用的示例代码。

<EditText
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:imeOptions="actionDone"
    android:singleLine="true"
    android:id="@+id/test_etx"
    android:hint="@string/hint"
    android:layout_below="@+id/bt3"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="29dp"
    android:layout_alignRight="@+id/etx"
    android:layout_alignEnd="@+id/etx"
    android:maxLength="10"
    />

【问题讨论】:

  • 尝试添加android:scrollbars="horizontal"
  • 或者您可以将编辑文本包装在水平滚动视图中。
  • 我也尝试过,但提示不是滚动。

标签: android android-edittext


【解决方案1】:

使您的 EditText 宽度 match_parent。把它放在一个水平滚动视图中。我试过了,它有效。如果您想要固定宽度,请为水平滚动视图提供固定宽度。像这样:

<HorizontalScrollView android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_below="@+id/bt3"
                      android:layout_alignParentLeft="true"
                      android:layout_alignParentStart="true"
                      android:layout_marginTop="29dp"
                      android:layout_alignRight="@+id/etx"
                      android:layout_alignEnd="@+id/etx">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:singleLine="true"
android:id="@+id/test_etx"
android:hint="@string/hint"
android:maxLength="10"/>
</HorizontalScrollView>

【讨论】:

  • 它也可以在应用程序中使用,但编辑文本的边框不正确。例如,如果文本滚动到左侧,则不显示右边框。如果不显示向左滚动。
  • 如果您有任何建议。
【解决方案2】:

首先您可以在editText 中添加一个滚动条,然后将文本放入editText 中,使用灰色字体颜色而不是提示,然后在editText 上放置一个OnClickListener。如果输入文本与提示匹配,则将其设置为“”,否则处理数据。

在值 res 中创建两个 EditText id 及其对应提示的数组。然后使用getResource() 获取两个数组。 使用

String str = view.getResources().getResourceName(id);
str = str.substring(str.lastIndexOf(":id/") + 4);

获取视图 ID。

将存储数组提示中的提示与输入文本匹配。我认为它将适用于所有布局。希望对您有所帮助。

【讨论】:

  • 在一个布局中,如果我更改一个编辑文本,我有多个编辑文本视图,我需要更改每个编辑文本。
  • 那么每个布局都有很长的提示??
  • 2 r 3 用于一种布局。
猜你喜欢
  • 2013-10-09
  • 2011-01-26
  • 2011-08-04
  • 1970-01-01
  • 2021-05-06
  • 2020-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多