Android表格行对齐到底部

时间:2015-01-01 16:22:50

标签: android alignment tablerow

我的应用中存在对齐问题。我想创建三个部分。 顶部是菜单,底部是菜单,屏幕中间是地图部分。但正如您在图片中看到的那样,我无法将第二个菜单与屏幕底部对齐

这是我的布局xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context="com.ufukugur.app.MainActivity"
    android:background="#000">
<!-- menu on the top -->
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:id="@+id/ustMenu">
        <TableRow
            android:layout_marginLeft="0dp"
            android:layout_marginTop="0dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:weightSum="7" >

            <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" >
                <ImageView
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:clickable="false"
                    android:gravity="left"
                    android:id="@+id/imgLogo"/>
            </RelativeLayout>

            <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" >
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="36dp"
                    android:clickable="true"
                    android:onClick="menuHarita"
                    android:gravity="center_horizontal"
                    android:src="@drawable/menunokta"
                    android:id="@+id/imgMenuNokta"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/imgMenuNokta"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="Sembol"
                    android:layout_alignParentBottom="true"
                    android:gravity="center_horizontal"
                    android:textColor="#fff" />
            </RelativeLayout>

            <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" >
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="36dp"
                    android:clickable="true"
                    android:onClick="menuHarita"
                    android:gravity="center_horizontal"
                    android:src="@drawable/menucizgi"
                    android:id="@+id/imgMenuCizgi"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/imgMenuCizgi"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="Rota"
                    android:gravity="center_horizontal"
                    android:textColor="#fff" />
            </RelativeLayout>

            <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" >
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="36dp"
                    android:clickable="true"
                    android:onClick="menuHarita"
                    android:gravity="center_horizontal"
                    android:src="@drawable/menubolge"
                    android:id="@+id/imgMenuBolge"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/imgMenuBolge"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="Bölge"
                    android:gravity="center_horizontal"
                    android:textColor="#fff" />
            </RelativeLayout>

            <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" >
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="36dp"
                    android:clickable="true"
                    android:onClick="menuHarita"
                    android:gravity="center_horizontal"
                    android:src="@drawable/menunotam"
                    android:id="@+id/imgMenuNotam"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/imgMenuNotam"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="Notam"
                    android:gravity="center_horizontal"
                    android:textColor="#fff" />
            </RelativeLayout>

            <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" >
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="36dp"
                    android:clickable="true"
                    android:onClick="menuHarita"
                    android:gravity="center_horizontal"
                    android:src="@drawable/menufir"
                    android:id="@+id/imgMenuFir"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/imgMenuFir"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="FIR"
                    android:gravity="center_horizontal"
                    android:textColor="#fff" />
            </RelativeLayout>

            <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" >
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="36dp"
                    android:clickable="true"
                    android:onClick="menuHarita"
                    android:gravity="center_horizontal"
                    android:src="@drawable/menutrafik"
                    android:id="@+id/imgMenuTrafik"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/imgMenuTrafik"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="Trafik"
                    android:gravity="center_horizontal"
                    android:textColor="#fff" />
            </RelativeLayout>
        </TableRow>
    </RelativeLayout>

<!-- map and other things middle of the screen -->
    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="60dp"
        android:layout_marginBottom="60dp"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_alignParentBottom="true" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="GPS bağlantısı sağlanıyor..."
        android:id="@+id/textKonum"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:textColor="#ff0"
        android:background="@color/black_overlay"/>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text=""
        android:id="@+id/textYakin"
        android:layout_alignParentBottom="true"
        android:gravity="center_horizontal"
        android:background="@color/black_overlay"/>

    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="50dp"
        android:clickable="true"
        android:onClick="notamClicked"
        android:src="@drawable/unlems"
        android:id="@+id/imgNotam"/>

    <ImageView
        android:layout_width="35dp"
        android:layout_height="35dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dp"
        android:layout_marginBottom="40dp"
        android:clickable="false"
        android:id="@+id/imageGSM"/>

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/hats_basla"
        android:clickable="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_marginRight="5dp"
        android:layout_marginTop="70dp"
        android:id="@+id/imbKayit" />

<!-- bottom menu -->
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:weightSum="6" >

        <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" >
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="36dp"
                android:clickable="true"
                android:onClick="menuHarita"
                android:gravity="center_horizontal"
                android:src="@drawable/menuharita"
                android:id="@+id/imgMenuHarita"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/imgMenuHarita"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Harita"
                android:layout_alignParentBottom="true"
                android:gravity="center_horizontal"
                android:textColor="#fff" />
        </RelativeLayout>

        <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" >
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="36dp"
                android:clickable="true"
                android:onClick="menuHarita"
                android:gravity="center_horizontal"
                android:src="@drawable/menuguncel"
                android:id="@+id/imgMenuGuncel"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/imgMenuGuncel"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Güncelle"
                android:gravity="center_horizontal"
                android:textColor="#fff" />
        </RelativeLayout>

        <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" >
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="36dp"
                android:clickable="true"
                android:onClick="menuHarita"
                android:gravity="center_horizontal"
                android:src="@drawable/menubilgi"
                android:id="@+id/imgMenuBilgi"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/imgMenuBilgi"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="HATS"
                android:gravity="center_horizontal"
                android:textColor="#fff" />
        </RelativeLayout>

        <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" >
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="36dp"
                android:clickable="true"
                android:onClick="menuHarita"
                android:gravity="center_horizontal"
                android:src="@drawable/menuayarlar"
                android:id="@+id/imgMenuAyarlar"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/imgMenuAyarlar"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Ayarlar"
                android:gravity="center_horizontal"
                android:textColor="#fff" />
        </RelativeLayout>

        <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" >
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="36dp"
                android:clickable="true"
                android:onClick="menuHarita"
                android:gravity="center_horizontal"
                android:src="@drawable/menuara"
                android:id="@+id/imgMenuAra"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/imgMenuAra"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Ara"
                android:gravity="center_horizontal"
                android:textColor="#fff" />
        </RelativeLayout>

        <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" >
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="36dp"
                android:clickable="true"
                android:onClick="menuHarita"
                android:gravity="center_horizontal"
                android:src="@drawable/menuradar"
                android:id="@+id/imgMenuRadar"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/imgMenuRadar"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Meteo"
                android:gravity="center_horizontal"
                android:textColor="#fff" />
        </RelativeLayout>
    </TableRow>
</RelativeLayout>

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以尝试这种经过修改的布局,它与您创建的布局完全不同,但结果可能与您想要的相同。

 <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <!-- TOP SIDE MENU AND OTHER VIEWS -->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

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

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="36dp"
                android:clickable="true"
                android:contentDescription="@null"
                android:gravity="center_horizontal"
                android:onClick="menuHarita"
                android:src="@drawable/ic_launcher" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:layout_gravity="center"
                android:text="Img1"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="#000" />
        </LinearLayout>


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

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="36dp"
                android:clickable="true"
                android:contentDescription="@null"
                android:gravity="center_horizontal"
                android:onClick="menuHarita"
                android:src="@drawable/ic_launcher" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Img2"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="#000" />
        </LinearLayout>

        // ADD YOUR REMAINING VIEWS HERE..........

    </LinearLayout>


    <!-- MIDDLE LAYOUT MAP AND OTHER VIEW -->

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <fragment
            android:id="@+id/mapView"
            android:name="com.google.android.gms.maps.MapFragment"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

        <TextView 
            android:id="@+id/firstTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="GPS bağlantısı sağlanıyor..." 
            android:layout_centerHorizontal="true"
            android:layout_alignParentTop="true"/>

        <TextView 
            android:id="@+id/firstTextView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="GPS bağlantısı sağlanıyor..." 
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"/>

         // ADD OTHER VIEWS HERE, BE CARE FULL THE PARENT LAYOUT IS RELATIVE LAYOUT
            SO, ADD REMAINING THREE IMAGE VIEWS ACCORDINGLY......  

    </RelativeLayout>


    <!-- LOWER LAYOUT AND OTHER VIEWS VIEWING HORIZONTALLY -->

     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="36dp"
                android:clickable="true"
                android:contentDescription="@null"
                android:gravity="center_horizontal"
                android:onClick="menuHarita"
                android:src="@drawable/ic_launcher" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="img1"
                android:layout_gravity="center"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="#000" />
        </LinearLayout>


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="36dp"
                android:clickable="true"
                android:contentDescription="@null"
                android:gravity="center_horizontal"
                android:onClick="menuHarita"
                android:src="@drawable/ic_launcher" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="img2"
                android:layout_gravity="center"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="#000" />
        </LinearLayout>

      // ADD OTHER VIEW HERE......

    </LinearLayout>



</LinearLayout>

注意:您需要用自己的ID替换我的ID和其他资源。只是为了测试这种布局       根据您的要求工作只需复制并粘贴我的布局并检查。并根据需要进行更改       你的要求。