开发者

cannot see button next to search box android

I'm having trouble when showing a button next to the search box. I'm using an auto complete text view and i don't know if this is due to the auto complete text view. How can i fix this. Here's what i got so far:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    >

    <AutoCompleteTextView 
        android:id="@+id/autocomplete"
        android:layout_width="fill_pare开发者_开发百科nt"
        android:layout_height="wrap_content"
        android:inputType="text"
        />

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

</LinearLayout>


To fix this, just add the tag android:layout_weight=1 to your AutoCompleteTextView.

This happens because android noticed you set the layout_width to fill_parent on your AutoCompleteTextView, and then it has no space for the Button left. Setting the weight to 1 means the textview will be "generous" and give as much space to any other components as they request, which in this case is limited to the width of the Button after is wrapped.


You are filling the parent width with your AutoCompleteTextView (thus pushing the Button out of screen width). Try to change this

<AutoCompleteTextView 
        android:id="@+id/autocomplete"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="text"
        />

into this

<AutoCompleteTextView 
        android:id="@+id/autocomplete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="text"
        />

And your Button should become visible. Here is a nice resource conserning layouts: Android Developer | Declaring Layouts

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜