簡體   English   中英

網格視圖上方的圖像和文本視圖

[英]Image and textview above gridview layout

我試圖在gridview上方放置4個圖像視圖和一個textview,我的布局應該這樣嗎 () (藍色文本視圖,橙色圖像視圖和下一個網格視圖)之間的距離也很重要。我進行了搜索,但無法實現我的視圖。 我稱為我的GridView的布局。 幫助我實現這一目標。 提前致謝。

// 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>

試試下面的代碼:

<?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>

暫無
暫無

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

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