newnewbie
newnewbie

Reputation: 1003

Android Layout - how to restrain textfield in size?

I have the following Layout:

<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>

however, the EditText is so big that the Listview is not even on the screen. I have tried around to change that, but to no avail. Is there a trick?

Second, is there a way to avoid having the name of the activity show up on the screen as title?

Thank you all for your help

Upvotes: 0

Views: 58

Answers (3)

Psypher
Psypher

Reputation: 10829

You have a problem in your edittext, you have kept the height as match parent and hence its occupying the entire screen, you will have to change it to wrap_content. To display the edittext and button next to each other wrap them in a layout.

<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>

Upvotes: 1

Dhruba Bose
Dhruba Bose

Reputation: 446

You can add Theme.Black.NoTitleBar Theme if you want to hide title from all the screen in the application.

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


    </application>

Upvotes: 1

NavinRaj Pandey
NavinRaj Pandey

Reputation: 1704

set the height of EditText to "wrap_content" and in AndroidMenifest.xml in your activity declaration do this to hide the title:

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

......

Upvotes: 1

Related Questions