2017-12-18 305 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"