2012-12-12 125 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" 

如果观点是足够小,适合在屏幕上