2017-12-18 319 views
0

我是Android新手。我正在閱讀關於線性佈局的Android官方文檔。獲取線性佈局錯誤

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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" 
android:orientation="vertical" 
android:paddingLeft="15dp" 
android:paddingRight="15dp" 
tools:context="com.example.hassan_microsoft.a2ndday18122017.MainActivity"> 

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="15dp" 
    android:paddingRight="15dp" 
    android:hint="@string/to"/> 

在這條線=>機器人:提示=「@字符串/到」 它給錯誤,而不是工作,我希望它的工作。 Picture1

這個預覽(圖片1)應該是結果,但我的發佈如下圖所示(圖片2)。 Picture2可能是什麼問題。?謝謝。

+1

將您的edittext高度match_parent更改爲wrap_content。 –

回答

1

試試這個讓你EditText HIGHT到android:layout_height="wrap_content"

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="15dp" 
    android:paddingRight="15dp" 
    android:hint="@string/to" 
    /> 

而且還 您需要在價值RES /價值/ String.xml如下面的代碼

<string name="to">To</string> 
0
創建一個新的字符串資源價值

你需要聲明@ string/to的值在你的strings.xml

  1. 轉至應用程序 - >水庫 - >數值 - > strings.xml中
  2. 創建一個名爲與字符串值一個新的字符串值,它應該是這樣的:

    示例應用程序

    <string name="to">To</string> 
    

一個更簡單的替代方案只需將您的提示值更改爲:

android:hint="To"