开发者

Android Layout does not display all my components

I am trying to display an EditText and a Button horizontally and below of them I want to display a List(ListView). I have try this but it seems it's only sees the first Layout and nothing else after.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientat开发者_如何转开发ion="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dip"
>  <LinearLayout 
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="4"> <EditText
android:id="@+id/search_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
/>
<Button 
android:id="@+id/search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go"
android:layout_weight="1"
/> </LinearLayout>  <!-- <EditText
android:id="@+id/testedit_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
/>
--> <ListView android:id="@+id/android:list"
      android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
<TextView android:id="@+id/text1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:textAppearance="?android:attr/textAppearanceLarge"    />    <TextView android:id="@+id/text2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:textAppearance="?android:attr/textAppearanceSmall"    /></LinearLayout>

I have also tried and the commented line (EditText) and also it is not showing me anything... Any idea? Thanks!


Add

layout_weight="1"

into your horizontal layout. And you will need to add similar lines in the TextViews at the bottom if you want to see those also.

Your current problem is that you set that one to fill_parent, so when it gets to the ListView, there is no space available.


you are using two nested LinearLayout with fillParent... you are doing it wrong. Why don't you use RelativeLayout?


Try this:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="1dip">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:weightSum="4"
        android:layout_height="wrap_content">
        <EditText
            android:id="@+id/search_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="3" />
        <Button
            android:id="@+id/search_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Go"
            android:layout_weight="1" />
    </LinearLayout>  <!-- <EditText android:id="@+id/testedit_txt" android:layout_width="wrap_content" 
        android:layout_height="wrap_content" android:layout_weight="3" /> -->
    <ListView
        android:id="@+id/android:list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_weight="1"/>
    <TextView
        android:id="@+id/text1"
        android:layout_width="fill_parent"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_height="wrap_content"
        android:text="qwe" />
    <TextView
        android:id="@+id/text2"
        android:layout_width="fill_parent"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:layout_height="wrap_content"
        android:text="qwe" />
</LinearLayout>


I'm assuming that you want the EditText and Button at the top, the two TextViews at the bottom, and the ListView to fill the available space in the middle. If that's the case then you need to tweak your layout_height's and add a android:layout_weight="1" to your ListView:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:padding="1dip">
    <LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent" android:weightSum="4"
        android:layout_height="wrap_content">
        <EditText android:id="@+id/search_txt" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_weight="3" />
        <Button android:id="@+id/search_button" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="Go"
            android:layout_weight="1" />
    </LinearLayout>  <!-- <EditText android:id="@+id/testedit_txt" android:layout_width="wrap_content" 
        android:layout_height="wrap_content" android:layout_weight="3" /> -->
    <ListView android:id="@+id/android:list" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_weight="1" />
    <TextView android:id="@+id/text1" android:layout_width="fill_parent"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_height="wrap_content" />
    <TextView android:id="@+id/text2" android:layout_width="fill_parent"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:layout_height="wrap_content" />
</LinearLayout>


Try this .... worked for me :

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pagelayout">

    <FrameLayout android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:id="@+id/content">
        <ListView android:id="@+id/android:list"
      android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    </FrameLayout>

    <LinearLayout android:layout_height="wrap_content"
        android:id="@+id/button_layout" 
        android:layout_width="fill_parent" android:gravity="center" android:layout_above="@+id/content">

        <Button android:id="@+id/search_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Go"
            android:layout_weight="1"
            />

            <EditText>
            android:id="@+id/search_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            </EditText>
    </LinearLayout>

    </RelativeLayout>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜