2016-07-27 34 views
1

在我的應用程序中我有固定大小的編輯文本,但提示大小超過編輯文本,所以提示不完全顯示。我想通過水平滾動完全顯示提示,但我沒有任何想法如何做到這一點。在編輯文本提示需要水平滾動

如果減小提示字體的大小,它將有所幫助,但我不想減小字體大小。

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

<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" 
    /> 
+0

嘗試添加'android:scrollbars =「horizo​​ntal」'。 –

+0

它不起作用 – YBDevi

+0

或者您可以將edittext包裝在水平滾動視圖中。 –

回答

0

使您的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> 
+0

它也適用於應用程序,但編輯文本的邊界不正確。如果文本滾動到左側,則不顯示右側邊框。如果滾動到右側,則不顯示。如果您有任何建議,請致電 – YBDevi

+0

。 – YBDevi

0

首先,你可以添加一個滾動的EDITTEXT然後把文字用灰色的字體顏色,而不是暗示編輯文本,然後把OnClickListener上EDITTEXT。如果輸入文本與提示匹配,則將其設置爲「」否則處理數據。

在值res中創建兩個EditText id數組及其對應的提示。然後使用getResource()獲取這兩個數組。 使用

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

獲取視圖ID。

匹配提示從存儲數組的提示輸入文本。我認爲這將是所有佈局的一般化。希望它有幫助。

+0

在一個佈局中,我有多個編輯文本視圖,如果我更改一個edittext我需要更改每個編輯文本。 – YBDevi

+0

所以每個佈局都有很長的提示? – Shubh

+0

2 r 3適用於一種佈局。 – YBDevi