Android视图布局组件在彼此之上

时间:2014-12-15 12:48:31

标签: java android android-layout layout

我在Android Activity的布局方面遇到了一些问题。所以基本上我有一个导航抽屉和两个活动。当我用框架布局包装所有这些布局时,布局工作得很好。但是,由于导航抽屉问题,我必须将框架布局移除到另一个xml布局中。然后从那里,我的布局都搞砸了。这是我的layout.xml:

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

    <com.esri.android.map.MapView
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        initExtent="21801.3, 25801.0, 33218.7, 44830.0" >
    </com.esri.android.map.MapView>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:layout_marginLeft="45dp" >

        <ImageView
            android:id="@+id/ivEventGuide"
            android:layout_width="230dp"
            android:layout_height="100dp"
            android:layout_gravity="center"
            android:src="@drawable/event_create_guide"
            android:visibility="gone" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <Button
            android:id="@+id/btnNewsFeed"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/lightred"
            android:minHeight="20dp"
            android:paddingBottom="5dp"
            android:text="News feed"
            android:textColor="#FFFFFF"
            android:textSize="13dp" />

        <LinearLayout
            android:id="@+id/llNewsFeed"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_below="@+id/btnNewsFeed"
            android:background="#FFFFFF"
            android:orientation="vertical"
            android:visibility="gone" >

            <ListView
                android:id="@+id/EventNewsFeedListview"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:listSelector="#F6CECE" >
            </ListView>
        </LinearLayout>

        <Button
            android:id="@+id/btnLegends"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/btnNewsFeed"
            android:background="#FFFFFF"
            android:minHeight="20dp"
            android:paddingBottom="5dp"
            android:text="Legends"
            android:textColor="@color/lightred"
            android:textSize="13dp" />

        <LinearLayout
            android:id="@+id/legendDiv"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_below="@+id/btnLegends"
            android:background="#fff"
            android:orientation="vertical"
            android:visibility="gone" >

            <TableLayout
                android:id="@+id/tableEvent"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:stretchColumns="1" >

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingTop="4dp" >

                    <ImageView
                        android:layout_width="0dp"
                        android:layout_height="30dp"
                        android:layout_gravity="right"
                        android:layout_weight="1"
                        android:adjustViewBounds="true"
                        android:src="@drawable/food" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="left"
                        android:paddingTop="10dp"
                        android:text="Food Event"
                        android:textColor="#000"
                        android:textSize="10dp" />

                    <ImageView
                        android:layout_width="0dp"
                        android:layout_height="30dp"
                        android:layout_gravity="right"
                        android:layout_weight="1"
                        android:adjustViewBounds="true"
                        android:src="@drawable/sport" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="left"
                        android:paddingTop="10dp"
                        android:text="Sport Event"
                        android:textColor="#000"
                        android:textSize="10dp" />
                </TableRow>

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingTop="2dp" >

                    <ImageView
                        android:layout_width="0dp"
                        android:layout_height="30dp"
                        android:layout_gravity="right"
                        android:layout_weight="1"
                        android:adjustViewBounds="true"
                        android:src="@drawable/races" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="left"
                        android:paddingTop="10dp"
                        android:text="Festival Celebration"
                        android:textColor="#000"
                        android:textSize="10dp" />

                    <ImageView
                        android:layout_width="0dp"
                        android:layout_height="30dp"
                        android:layout_gravity="right"
                        android:layout_weight="1"
                        android:adjustViewBounds="true"
                        android:src="@drawable/discussion" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="left"
                        android:paddingTop="10dp"
                        android:text="Chit Chat Session"
                        android:textColor="#000"
                        android:textSize="10dp" />
                </TableRow>
            </TableLayout>
        </LinearLayout>

        <TextView
            android:id="@+id/tvSearchTitle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/llSearch"
            android:background="@color/lightred"
            android:gravity="center"
            android:paddingBottom="5dp"
            android:text="Address Search"
            android:textColor="#FFFFFF" >
        </TextView>

        <LinearLayout
            android:id="@+id/llSearch"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="#FFFFFF"
            android:orientation="horizontal"
            android:padding="5dp"
            android:weightSum="1" >

            <EditText
                android:id="@+id/searchAddrET"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_weight="0.8"
                android:hint="Enter search address, eg. postal code"
                android:textSize="12dp" />

            <Button
                android:id="@+id/btnSearchAddr"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_weight="0.2"
                android:background="@color/lightred"
                android:minHeight="30dp"
                android:text="Search"
                android:textColor="#FFFFFF"
                android:textSize="12dp" />
        </LinearLayout>

        <TextView
            android:id="@+id/tvDirectionTitle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/llDirection"
            android:background="@color/lightred"
            android:gravity="center"
            android:paddingBottom="5dp"
            android:text="Direction"
            android:textColor="#FFFFFF"
            android:visibility="gone" >
        </TextView>

        <LinearLayout
            android:id="@+id/llDirection"
            android:layout_width="fill_parent"
            android:layout_height="80dp"
            android:layout_alignParentBottom="true"
            android:background="#FFFFFF"
            android:padding="5dp"
            android:visibility="gone" >

            <ScrollView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/tvDirection"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" >
                </TextView>
            </ScrollView>
        </LinearLayout>
    </RelativeLayout>

</LinearLayout>

当它正常工作时,我用地图布局包裹地图视图和布局的休止符。然后在我扩展导航抽屉的类中:

public class EventMain extends NavigationDrawer {

public static MapView mMapView = null;
ArcGISTiledMapServiceLayer tileLayer;
LocationManager locationManager;
public static GraphicsLayer graphicsLayer = null;
public static Callout callout;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ViewGroup content = (ViewGroup) findViewById(R.id.event_frame);
    getLayoutInflater().inflate(R.layout.event_main, content, true);   
}

我现在遇到的问题是所有其他组件都没有显示在地图视图的顶部。任何指南?

提前致谢。

1 个答案:

答案 0 :(得分:1)

您应该考虑使用RelativeLayout来重叠视图。 RelativeLayout内的视图可以相对于其父和/或兄弟姐妹定位。 LinearLayout将按顺序排列视图,不允许重叠。