簡體   English   中英

android:layout_below =不會在ImageButtons下方設置TextViews

[英]android:layout_below= Does Not Set TextViews Below ImageButtons

我不確定為什么,但是在我的linearlayout android:layout_below=沒有在ImageButtons下方設置TextViews

我知道我已經忽略了一些東西,但是我不確定那到底是什么。

在此處輸入圖片說明

任何建議表示贊賞。

  <?xml version="1.0" encoding="UTF-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/layout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:weightSum="1" >

            <View
                android:id="@+id/view1"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0.3" />

            <ImageButton
                android:id="@+id/photos"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.1"
                android:src="@drawable/photos" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/photos"
                android:layout_marginTop="17dp"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <ImageButton
                android:id="@+id/audio"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.1"
                android:src="@drawable/audio" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/audio"
                android:layout_marginTop="17dp"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <ImageButton
                android:id="@+id/written"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.1"
                android:src="@drawable/written" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/written"
                android:layout_marginTop="17dp"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <ImageButton
                android:id="@+id/video"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.1"
                android:src="@drawable/video" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/video"
                android:layout_marginTop="17dp"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <View
                android:id="@+id/view1"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0.3" />
        </LinearLayout>

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="800dp"
            android:layout_height="100dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="48dp"
            android:src="@drawable/icon_e" />

    </RelativeLayout>

嘗試這個..

android:layout_below僅適用於RelativeLayout不適用於LinearLayout

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true" >

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/photos"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:src="@drawable/photos" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="17dp"
                android:gravity="center"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/audio"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:src="@drawable/audio" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="17dp"
                android:gravity="center"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/written"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:src="@drawable/written" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="17dp"
                android:gravity="center"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/video"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:src="@drawable/video" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="17dp"
                android:gravity="center"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>
    </LinearLayout>

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="800dp"
        android:layout_height="100dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="48dp"
        android:src="@drawable/icon_e" />

</RelativeLayout>

android:layout_below僅在RelativeLayout內部起作用

您必須使用RalativeLayout而不是LinearLayout

LinearLayout不允許使用layout_below屬性。

如下將每個相關的ImageButtonTextView放入帶有android:orientation="vertical"另一個LinearLayout ...

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ImageButton
            android:id="@+id/photos"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/photos" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/photos"
            android:layout_marginTop="17dp"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </LinearLayout>

因此,您更新后的布局可以如下...

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:gravity="center"
        android:orientation="horizontal"
        android:weightSum="1" >

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/photos"
                android:layout_width="wrap_content"
                android:layout_height="0dip"
                android:layout_weight="1"
                android:src="@drawable/photos" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="17dp"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/audio"
                android:layout_width="wrap_content"
                android:layout_height="0dip"
                android:layout_weight="1"
                android:src="@drawable/audio" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="17dp"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/written"
                android:layout_width="wrap_content"
                android:layout_height="0dip"
                android:layout_weight="1"
                android:src="@drawable/written" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="17dp"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/video"
                android:layout_width="wrap_content"
                android:layout_height="0dip"
                android:layout_weight="1"
                android:src="@drawable/video" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="17dp"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>
    </LinearLayout>

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="800dp"
        android:layout_height="100dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="48dp"
        android:src="@drawable/icon_e" />

</RelativeLayout>

暫無
暫無

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

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