[英]Android layout (TextView)
我是Android開發的新手,對布局設計有一些疑問。 我有以下代碼,但它不能按我的意願工作。 我想讓圖像視圖顯示我拍攝的照片,並在其下方顯示一個用於輸入數據的文本框。 但是,此時,圖像占據整個屏幕,我無法找到我的文本框。 請善意的建議。 謝謝!
<?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>
將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>
問題是
android:layout_height ="fill _parent"
這使得它占據整個父空間即整個屏幕
將高度設置為特定值dp,px等。或者使用
android:layout_height="wrap_content"
如果視圖小到足以適合屏幕
使用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>
<ImageView android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/desc"/>
像這樣為ImageView添加重量。 它會工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.