布局问题。使用表格时遇到问题

时间:2013-10-02 02:52:11

标签: android xml

我想做3个大栏目来分开3个活动。但是我不知道如何将第二列分成我想在其中放置地图的地方。任何帮助表示赞赏!谢谢!

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

    <!----- 1 main table to split into 3 columns ------>
    <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

        <!----- 1 row ------>
        <TableRow
                android:id="@+id/tableRow4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                 >
            <!-----@@@@@@@@@@@@@@@@@@@@@@@@- Column 1 @@@@@@@@@@@@@@@@@@@@@@@@------>
        <TableLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            >

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

                <Button
                    android:id="@+id/connect_button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="horizontal"
                    android:text="Connect" />

                <Button
                    android:id="@+id/disconnect_button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:text="Disconnect" />
            </LinearLayout>

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

                <TextView
                    android:id="@+id/status_button"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="#FFFF00"
                    android:gravity="center"
                    android:orientation="horizontal" />
            </LinearLayout>

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

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

                <Button
                    android:id="@+id/s1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="horizontal"
                    android:text="S1" />

                <Button
                    android:id="@+id/s2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="horizontal"
                    android:text="S2" />

                <ImageButton
                    android:id="@+id/configure"
                    android:layout_width="81dp"
                    android:layout_height="wrap_content"
                    android:onClick="openConfigurations"
                    android:src="@android:drawable/ic_menu_manage" />
            </LinearLayout>

            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <TableRow
                    android:id="@+id/tableRow2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >

                    <Gallery
                        android:id="@+id/gallery2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                    <ImageButton
                        android:id="@+id/up"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="2"
                        android:src="@drawable/up" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >

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

                    <ToggleButton
                        android:id="@+id/toggle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="2"
                        android:layout_gravity="center"
                        android:background="@drawable/check"
                        android:textOff=""
                        android:textOn="" />

                    <ImageButton
                        android:id="@+id/right"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="3"
                        android:src="@drawable/right" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >

                    <ImageButton
                        android:id="@+id/down"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="2"
                        android:src="@drawable/down" />
                </TableRow>
            </TableLayout>
    </TableLayout>


                    <!-----@@@@@@@@@@@@@@@@- Column 2 @@@@@@@@@@@@@@@@@------>
        <RelativeLayout
            android:id="@+id/gridView1"
            android:layout_width="match_parent"
            android:layout_height="500dp"
            android:layout_marginTop="27dp"
            android:layout_column="0"
            android:layout_gravity="center"
            android:layout_row="9"
            android:background="#FFFFAA" >

        <com.example.project.image_map
            android:id="@+id/mapView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center" />

     </RelativeLayout>

                <!-----@@@@@@@@@@@@@@@@- Column 3 @@@@@@@@@@@@@@@@@------>
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" 
            android:layout_column="3"/>

    </TableRow>
    </TableLayout>



</LinearLayout>

我不确定,因为我试图在相对布局中放置“android:layout_column =”2“并且存在错误。我应该如何定义哪个列中的哪个活动?它不像图像或者只是我在layout_column中添加的按钮..

2 个答案:

答案 0 :(得分:1)

在RelativeLayout中,UI组件位置相对于其他UI组件和父容器。你不能在RelativeLayout中使用android:layout_column。只要在java活动类中添加对它的引用,就可以为任何列定义任何活动。

答案 1 :(得分:0)

我不确定你在寻找什么。您可能想要做的事情不同。

首先,这是你的布局在风景中的样子: current layout/landscape

然后问题是,它有什么问题?你觉得它怎么样?我可以假设一些事情,但它需要更多的指导。

  • 在纵向方向上,没有足够的空间来显示如此复杂的屏幕。您可以在清单中设置此活动应仅以横向模式显示,并且不应更改方向,无论用户做什么。在清单中设置此方法的方法:<activity android:name="+yourActivityClass+" android:screenOrientation="landscape"></activity>
  • 也许您想将这三个区域分成三个不同的屏幕,可以在它们之间切换,例如从左到右擦拭。在这种情况下,您最好使用Fragments。在Eclipse中,当您创建一个新的Activity时,它会询问您所需的导航类型并创建一个骨架。