簡體   English   中英

xml中聲明元素的順序的重要性是什么

[英]What is the importance about sequence of declaring elements in xml

我只是在學習Android編程,所以我決定編寫一個有關計算人的BMI的簡單應用程序! 我的問題是,當我先聲明TextView和Button然后再聲明ImageView時,所有三個元素在縱向和橫向模式下都適合屏幕:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context="com.example.bmicalculator.MainActivity">
<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="BMI Calculator" />
<Button
    android:id="@+id/button1"
    android:layout_width="195dp"
    android:layout_height="33dp"
    android:text="Start"
    android:textSize="15dp" />
<ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/splash" />

http://www.imageupload.co.uk/images/2015/01/30/4H6T2c.jpg http://www.imageupload.co.uk/images/2015/01/30/3VQ0uM.jpg

但是,當我更改序列並在橫向模式下ImageView輸出更改后聲明TextView和Button時,TextView消失了! 只有按鈕顯示和帶有頂部設置欄的圖像覆蓋的一半:

http://www.imageupload.co.uk/images/2015/01/30/2kP5Os.jpg

但是還是人像模式還可以

http://www.imageupload.co.uk/images/2015/01/30/1l90d.jpg

那么,當我更改在xml中聲明這些元素的順序時,會發生什么變化? 以及我該如何解決。 日Thnx

嘗試這個

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.bmicalculator.MainActivity">

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:adjustViewBounds="true"
    android:src="@drawable/splash"
    android:layout_above="@+id/textView1" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="BMI Calculator"
    android:layout_above="@+id/button1"
    android:layout_centerHorizontal="true" />

<Button
    android:id="@+id/button1"
    android:layout_width="195dp"
    android:layout_height="33dp"
    android:text="Start"
    android:textSize="15dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />

</RelativeLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM