簡體   English   中英

Android Layout-如何限制文本字段的大小?

[英]Android Layout - how to restrain textfield in size?

我有以下布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.myapp.ViewActivity"
tools:ignore="MergeRootFrame" >
<TextView
    android:id="@+id/tex"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/myText" />
<EditText
android:id="@+id/textfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/but"
android:layout_centerVertical="true"
android:inputType="text"/>  
<Button
 android:id="@+id/but"
 android:layout_height="wrap_content"
 android:layout_width="wrap_content"
 android:text="@string/suchen"
 android:layout_below="@+id/tex"
 android:layout_alignParentRight="true"
 android:onClick="search" />
<ListView
android:id="@+id/v"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textfield">    
</ListView>
</RelativeLayout>

但是,EditText太大,以至於Listview甚至不在屏幕上。 我已經嘗試過更改它,但無濟於事。 有把戲嗎?

其次,是否有一種方法可以避免將活動名稱作為標題顯示在屏幕上?

謝謝大家的幫助

將EditText的高度設置為“ wrap_content”,並在AndroidMenifest.xml中的活動聲明中執行以下操作以隱藏標題:

<activity android:name=".Activity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">

......

如果要在應用程序的所有屏幕中隱藏標題,則可以添加Theme.Black.NoTitleBar主題。

 <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Black.NoTitleBar" >


    </application>

您的編輯文本中有問題,您將高度保持為匹配父級,因此它占據了整個屏幕,您必須將其更改為wrap_content。 要顯示編輯文本和按鈕彼此相鄰,請將其包裝在布局中。

<LinearLayout
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:orientation="horizontal">
<EditText
android:id="@+id/textfield"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:inputType="text"/>  
<Button
android:id="@+id/but"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/suchen"
android:onClick="search" />    
</LinearLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM