简体   繁体   中英

Image and textview above gridview layout

Am trying to place 4 image views and one textview above gridview and my layout should me like this () (blue-textview, orange- imageview and next gridview) and inbetween the gap is also essential.I searched but couldn't achieve my view. I referred here for my gridview layout. Help me in achieving this. Thanks in advance.

// try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:padding="10dp">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:gravity="right">

        <ImageView
                android:layout_width="100dp"
                android:layout_height="50dp"
                android:src="@drawable/ic_launcher"
                android:adjustViewBounds="true"
                android:scaleType="fitXY"/>
    </LinearLayout>

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:layout_marginTop="10dp">

        <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:src="@drawable/ic_launcher"
                android:adjustViewBounds="true"
                android:scaleType="fitXY"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="textview"/>
    </LinearLayout>

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:layout_marginTop="10dp">

        <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:src="@drawable/ic_launcher"
                android:adjustViewBounds="true"
                android:scaleType="fitXY"/>

        <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:src="@drawable/ic_launcher"
                android:adjustViewBounds="true"
                android:scaleType="fitXY"/>
    </LinearLayout>

    <GridView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginTop="20dp"
            android:layout_weight="1">

    </GridView>

</LinearLayout>

Try below code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/layoutHead"
        android:layout_width="fill_parent"
        android:layout_height="match_parent" >

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

            <ImageView
                android:id="@+id/imgOrange"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_margin="5dip"
                android:background="@drawable/ic_launcher" />
        </RelativeLayout>

        <LinearLayout
            android:id="@+id/linearmain"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/linear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/imgOrange"
                android:orientation="horizontal" >

                <ImageView
                    android:id="@+id/imgOrange1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="5dip"
                    android:background="@drawable/ic_launcher" />

                <TextView
                    android:id="@+id/txtTemp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:gravity="center_vertical"
                    android:text="test" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/linear1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/imgOrange"
                android:orientation="horizontal" >

                <ImageView
                    android:id="@+id/imgOrange2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="5dip"
                    android:background="@drawable/ic_launcher" />

                <TextView
                    android:id="@+id/txtTemp1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:gravity="center_vertical"
                    android:text="test" />
            </LinearLayout>

            <GridView
                android:id="@+id/gridview"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:columnWidth="90dp"
                android:gravity="center"
                android:horizontalSpacing="10dp"
                android:numColumns="auto_fit"
                android:smoothScrollbar="true"
                android:stretchMode="columnWidth"
                android:verticalSpacing="10dp" />
        </LinearLayout>
    </RelativeLayout>

</LinearLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM