简体   繁体   中英

Android xml layout about spinner,textview and imageview

I am trying to create a certain layout,I hope it same as picture.

在此处输入图片说明

But textview and imageview layout are ran out boundaries. How can I fix it ? I hope textview and imageview can under spinner. This is my current code,thanks

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

    <Spinner
        android:id="@+id/spinner_show"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15px"
        android:drawSelectorOnTop="true" />

    <ImageView
        android:id="@+id/icon1"
        android:layout_marginTop="130px"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_centerVertical="true"       
        android:background="#777"
        android:contentDescription="@string/app_name"
        android:padding="3dp" />

    <LinearLayout
        android:layout_width="185dp"
        android:layout_height="86dp"
        android:layout_marginTop="130px"
        android:gravity="center_vertical"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/itemname"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dip"
            android:maxLines="3"
            android:text="@string/itemname"
            android:textSize="14dp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/detil"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:maxLines="1"
            android:text="@string/detil"
            android:textColor="@android:color/black"
            android:textSize="12dp" />
    </LinearLayout>

    <ImageView
        android:id="@+id/arrow"
        android:layout_width="wrap_content"
        android:layout_height="80dp"
        android:layout_marginRight="5dp"
        android:contentDescription="@string/app_name"
        android:src="@drawable/arrow_next" />

</LinearLayout>

You can try as follows...

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

    <Spinner
        android:id="@+id/spinner_show"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15px"
        android:drawSelectorOnTop="true" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/icon1"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:background="#777"
            android:contentDescription="@string/app_name"
            android:padding="3dp" />

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/itemname"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dip"
                android:maxLines="3"
                android:text="@string/itemname"
                android:textSize="14dp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/detil"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:maxLines="1"
                android:text="@string/detil"
                android:textColor="@android:color/black"
                android:textSize="12dp" />
        </LinearLayout>

        <ImageView
            android:id="@+id/arrow"
            android:layout_width="wrap_content"
            android:layout_height="80dp"
            android:layout_marginRight="5dp"
            android:contentDescription="@string/app_name"
            android:src="@drawable/arrow_next" />
    </LinearLayout>

</LinearLayout>

try this..........

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

    <Spinner
        android:id="@+id/spinner_show"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15px"
        android:drawSelectorOnTop="true" />
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_marginTop="100px"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    >
    <ImageView
        android:id="@+id/icon1"

        android:layout_width="80dp"
        android:layout_height="80dp"

        android:background="#777"
        android:contentDescription="@string/app_name"
        android:padding="3dp" />

    <LinearLayout
        android:layout_width="185dp"
        android:layout_height="86dp"

        android:gravity="center_vertical"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/itemname"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dip"
            android:maxLines="3"
            android:text="itemname"
            android:textSize="14dp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/detil"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:maxLines="1"
            android:text="detil"
            android:textColor="@android:color/black"
            android:textSize="12dp" />
    </LinearLayout>

    <ImageView
        android:id="@+id/arrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp"
        android:contentDescription="@string/app_name"
        android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>

here is your layout ...

<?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:orientation="vertical" >

    <Spinner
        android:id="@+id/spinner_show"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15px"
        android:drawSelectorOnTop="true" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:orientation="horizontal"
        android:weightSum="3" >

        <ImageView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".5"
            android:background="#ababab" />

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:gravity="center"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/itemname"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:gravity="center"
                android:text="hello text"
                android:textSize="14sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/detil"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:gravity="center"
                android:text="hello text"
                android:textColor="@android:color/black"
                android:textSize="12sp" />
        </LinearLayout>

        <ImageView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".5"
            android:background="#ababab" />
    </LinearLayout>

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