2012-09-30 21 views
1
<?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:background="@color/bkgrndclr"> 

    <Button 
     android="@+id/imgbtn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Search Images" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" /> 
    <Button 
     android="@id/imgbtn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Search Web" 
     android:layout_alignBottom="@id/imgbtn" 
     android:layout_toLeftOf="@id/imgbtn" /> 
    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/imgbtn" 
     android:layout_alignRight="@id/imgbtn" /> 
</LinearLayout> 

我將按鈕設置到視圖的底部以及它們上方的文本框中,但爲什麼都是線性顯示。按鈕搜索圖像首先顯示然後搜索網頁然後是文本框,它們不位於底部,這不是我想要的。在主佈局上定位對象意外失敗

+0

變化的LinearLayout到RelativeLayout的 –

+0

但一個按鈕消失,文本框的Movex到視圖 –

回答

0

您還沒有描述你想要什麼......但我選擇了猜測,你想在屏幕上像這樣的底部佈局:

|            | 
| (EditText         ) | 
|       (Button) (Button) | 
----------------------------------------------- 

佈局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/bkgrndclr" 
    > 

    <Button 
     android:id="@+id/btnImages" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:text="Search Images" 
     /> 

    <Button 
     android:id="@+id/btnWeb" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_toLeftOf="@+id/btnImages" 
     android:text="Search Web" 
     /> 

    <EditText 
     android:id="@+id/search" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/btnImages" 
     android:inputType="text" 
     /> 

</RelativeLayout> 
0

在第二個按鈕中,將按鈕的ID更改爲"[email protected]/imgbtn1",以便它不會與第一個按鈕相沖突。

變化android:layout_alignBottom="@id/imgbtn"變爲android:layout_alignParentBottom="true"

你想在哪裏使用EditText?

+0

謝謝塔米爾的頂部,我希望它是以上兩個按鈕,但應該是在底部 –

+0

哦,是的,一個d將android =「@ + id/imgbtn」更改爲android:id =「@ + id/imgbtn」(當然還有其他ID):) –

0

如果你的瀏覽父親的LinearLayout「機器人:layout_alignParentBottom =」真「」已經沒有任何意義...... 您需要的線性變化,以相對 如果你想要的EditText是按鈕上面給它:

android:layout_above="@id/imgbtn" 

給你的按鈕提供不同的ID!並把它們變成alignParentBottom