2012-12-12 120 views
1

我是android開發新手,對佈局設計有些疑問。我有以下代碼,但它不工作,因爲我想。我希望圖像視圖顯示我拍攝的照片和下方的照片,供用戶輸入數據的文本框。然而,在這一刻,圖像佔用了整個屏幕,我找不到我的文本框。請提供建議。謝謝!Android佈局(TextView)

<?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:id="@+id/linear"> 

    <ImageView android:id="@+id/imageView1" 
     android:layout_width="fill_parent" android:layout_height="fill_parent" 
     android:contentDescription="@string/desc"/> 

    <EditText 
     android:id="@+id/editTextSimple1" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent"> 
     <requestFocus /> 
    </EditText> 

</LinearLayout> 

回答

1

使用RelativeLayout的替代的LinearLayout和使用下面的XML代碼而不是你的XML代碼,它會解決你的問題。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linear" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@+id/editTextSimple1" 
     android:contentDescription="desc" /> 

    <EditText 
     android:id="@+id/editTextSimple1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" > 

     <requestFocus /> 
    </EditText> 

</RelativeLayout> 
+0

嗨Dipak,我該如何增加imageView和EditText之間的間距? – iceraven

+1

@iceraven設置ImageView的layout_marginBottom屬性並嘗試。 –

+0

是的,這解決了我的問題。謝謝! – iceraven

1

變化ImageView的佈局高度layout_height="wrap_content"
隨着layout_height = 「FILL_PARENT」,圖像將採取所有的空間。

<?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:id="@+id/linear"> 

    <ImageView android:id="@+id/imageView1" 
     android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
     android:contentDescription="@string/desc"/> 

    <EditText 
     android:id="@+id/editTextSimple1" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent"> 
     <requestFocus /> 
    </EditText> 

</LinearLayout> 
0
<ImageView android:id="@+id/imageView1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:contentDescription="@string/desc"/> 

重量添加到您的ImageView這樣。它會工作。

1

問題是

android:layout_height ="fill _parent" 

這使得佔據整個父空間即整個屏幕

要麼將​​高度設置爲DP,PX等的特定值或使用

android:layout_height="wrap_content" 

如果觀點是足夠小,適合在屏幕上