需要适合每个设备上的LinearLayout图标

时间:2016-11-08 09:38:51

标签: android android-layout android-studio icons android-linearlayout

我希望至少有人会尝试帮助我:)。

我是初学者,对不起我的英语。

我的问题: 我需要在每台设备上安装这个线性布局,我不知道它是如何(它适合我的手机,但我认为它不适合其他设备)

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:layout_marginBottom="@dimen/spacing_medium"
    android:layout_marginLeft="@dimen/spacing_middle"
    android:layout_marginRight="@dimen/spacing_middle"
    android:layout_marginTop="@dimen/spacing_large"
    app:cardCornerRadius="@dimen/card_corner_radius"
    app:cardElevation="@dimen/elevation_card">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/spacing_medium"
        android:weightSum="1">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="66dp"
            android:layout_height="fill_parent"
            android:id="@+id/linearLayout2"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:gravity="center_horizontal"
            android:onClick="clickLayout"
            android:clickable="true"
            android:background="?attr/selectableItemBackground">

            <ImageView
                android:layout_width="@dimen/spacing_mlarge"
                android:layout_height="@dimen/spacing_mlarge"
                android:layout_margin="@dimen/spacing_middle"
                android:src="@drawable/ic_icon"
                android:tint="@color/grey_hard" />

            <TextView

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Check in"
                android:id="@+id/checkin"
                android:textColor="@color/material_grey_800"
                android:gravity="center"
                android:singleLine="true"
                android:layout_weight="0"
                android:ellipsize="end"
                android:textSize="12sp"/>
        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="66dp"
            android:layout_height="fill_parent"
            android:id="@+id/linearLayout4"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:gravity="center_horizontal"
            android:onClick="clickLayout"
            android:clickable="true"
            android:background="?attr/selectableItemBackground"

            >


            <ImageView
                android:layout_width="@dimen/spacing_mlarge"
                android:layout_height="@dimen/spacing_mlarge"
                android:layout_margin="@dimen/spacing_middle"
                android:src="@drawable/ic_icon"
                android:tint="@color/grey_hard" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Add photo"
                android:id="@+id/addchillspotphoto"
                android:textColor="@color/material_grey_800"
                android:gravity="center"
                android:singleLine="true"
                android:layout_weight="0"
                android:ellipsize="end"
                android:textSize="12sp"/>
        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="66dp"
            android:layout_height="fill_parent"
            android:id="@+id/linearLayout5"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:gravity="center_horizontal"
            android:onClick="clickLayout"
            android:clickable="true"
            android:background="?attr/selectableItemBackground"
            >


            <ImageView
                android:layout_width="@dimen/spacing_mlarge"
                android:layout_height="@dimen/spacing_mlarge"
                android:layout_margin="@dimen/spacing_middle"
                android:src="@drawable/ic_icon"
                android:tint="@color/grey_hard" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Report"
                android:id="@+id/reportchillspot"
                android:textColor="@color/material_grey_800"
                android:gravity="center"
                android:singleLine="true"
                android:layout_weight="0"
                android:ellipsize="end"
                android:textSize="12sp"/>
        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="66dp"
            android:layout_height="fill_parent"
            android:id="@+id/linearLayout6"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:gravity="center_horizontal"
            android:onClick="clickLayout"
            android:clickable="true"
            android:background="?attr/selectableItemBackground"
            >


            <ImageView
                android:layout_width="@dimen/spacing_mlarge"
                android:layout_height="@dimen/spacing_mlarge"
                android:layout_margin="@dimen/spacing_middle"
                android:src="@drawable/ic_icon"
                android:tint="@color/grey_hard" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Rate"
                android:id="@+id/rate_chillspot"
                android:textColor="@color/material_grey_800"
                android:gravity="center"
                android:singleLine="true"
                android:layout_weight="0"
                android:ellipsize="end"
                android:textSize="12sp"/>
        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="66dp"
            android:layout_height="fill_parent"
            android:id="@+id/linearLayout7"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:gravity="center_horizontal"
            android:onClick="clickLayout"
            android:clickable="true"
            android:background="?attr/selectableItemBackground"
            >


            <ImageView
                android:layout_width="@dimen/spacing_mlarge"
                android:layout_height="@dimen/spacing_mlarge"
                android:layout_margin="@dimen/spacing_middle"
                android:src="@drawable/ic_icon"
                android:tint="@color/grey_hard" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="WorkOmg"
                android:id="@+id/future_distance"
                android:textColor="@color/material_grey_800"
                android:gravity="center"
                android:singleLine="true"
                android:layout_weight="0"
                android:ellipsize="end"
                android:textSize="12sp"/>
        </LinearLayout>
    </LinearLayout>
</android.support.v7.widget.CardView>

How it looks in android emulator

非常感谢你们寻求帮助,我尽我所能,但我不知道......

//编辑:

以下是结果:(不工作:/)

click here for screenshots

2 个答案:

答案 0 :(得分:0)

试试这个:

只需根据您的选择替换图标和标题。

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

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

        <ImageView
            android:id="@+id/tab1_icon"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:scaleType="fitCenter"
            android:src="@mipmap/ic_launcher"/>

        <TextView
            android:id="@+id/tab1_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Title"
            android:textSize="14sp"
            android:lines="1"
            android:gravity="center_horizontal"/>

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

        <ImageView
            android:id="@+id/tab2_icon"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:scaleType="fitCenter"
            android:src="@mipmap/ic_launcher"/>

        <TextView
            android:id="@+id/tab2_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Title"
            android:textSize="14sp"
            android:lines="1"
            android:gravity="center_horizontal"/>

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

        <ImageView
            android:id="@+id/tab3_icon"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:scaleType="fitCenter"
            android:src="@mipmap/ic_launcher"/>

        <TextView
            android:id="@+id/tab3_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Title"
            android:textSize="14sp"
            android:lines="1"
            android:gravity="center_horizontal"/>

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

        <ImageView
            android:id="@+id/tab4_icon"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:scaleType="fitCenter"
            android:src="@mipmap/ic_launcher"/>

        <TextView
            android:id="@+id/tab4_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Title"
            android:textSize="14sp"
            android:lines="1"
            android:gravity="center_horizontal"/>

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

        <ImageView
            android:id="@+id/tab5_icon"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:scaleType="fitCenter"
            android:src="@mipmap/ic_launcher"/>

        <TextView
            android:id="@+id/tab5_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Title"
            android:textSize="14sp"
            android:lines="1"
            android:gravity="center_horizontal"/>

    </LinearLayout>
</LinearLayout>

我希望这会对你有所帮助。

答案 1 :(得分:0)

仅为每个android:layout_weight=".2"添加android:layout_width=".0dp"并更改LinearLayout,因为0.2 *(5 LinearLayout)为1,这是您的android:weightSum="1"

试试这段代码..

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

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_marginBottom="@dimen/spacing_medium"
        android:layout_marginLeft="@dimen/spacing_middle"
        android:layout_marginRight="@dimen/spacing_middle"
        android:layout_marginTop="@dimen/spacing_large"
        app:cardCornerRadius="@dimen/card_corner_radius"
        app:cardElevation="@dimen/elevation_card">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="horizontal"
            android:padding="@dimen/spacing_medium"
            android:weightSum="1">

            <LinearLayout
                android:id="@+id/linearLayout2"
                android:layout_width=".0dp"
                android:layout_height="fill_parent"
                android:layout_weight=".2"
                android:background="?attr/selectableItemBackground"
                android:clickable="true"
                android:gravity="center_horizontal"
                android:onClick="clickLayout"
                android:orientation="vertical"
                android:paddingLeft="5dp"
                android:paddingRight="5dp">

                <ImageView
                    android:layout_width="@dimen/spacing_mlarge"
                    android:layout_height="@dimen/spacing_mlarge"
                    android:layout_margin="@dimen/spacing_middle"
                    android:src="@drawable/com_facebook_profile_picture_blank_portrait" />

                <TextView

                    android:id="@+id/checkin"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0"
                    android:ellipsize="end"
                    android:gravity="center"
                    android:singleLine="true"
                    android:text="Check in"
                    android:textColor="@color/material_grey_800"
                    android:textSize="12sp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/linearLayout4"
                android:layout_width=".0dp"
                android:layout_height="fill_parent"
                android:layout_weight=".2"
                android:background="?attr/selectableItemBackground"
                android:clickable="true"
                android:gravity="center_horizontal"
                android:onClick="clickLayout"
                android:orientation="vertical"
                android:paddingLeft="5dp"
                android:paddingRight="5dp">

                <ImageView
                    android:layout_width="@dimen/spacing_mlarge"
                    android:layout_height="@dimen/spacing_mlarge"
                    android:layout_margin="@dimen/spacing_middle"
                    android:src="@drawable/com_facebook_profile_picture_blank_portrait"
                    android:tint="@color/grey_hard" />

                <TextView
                    android:id="@+id/addchillspotphoto"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0"
                    android:ellipsize="end"
                    android:gravity="center"
                    android:singleLine="true"
                    android:text="Add photo"
                    android:textColor="@color/material_grey_800"
                    android:textSize="12sp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/linearLayout5"
                android:layout_width=".0dp"
                android:layout_height="fill_parent"
                android:layout_weight=".2"
                android:background="?attr/selectableItemBackground"
                android:clickable="true"
                android:gravity="center_horizontal"
                android:onClick="clickLayout"
                android:orientation="vertical"
                android:paddingLeft="5dp"
                android:paddingRight="5dp">

                <ImageView
                    android:layout_width="@dimen/spacing_mlarge"
                    android:layout_height="@dimen/spacing_mlarge"
                    android:layout_margin="@dimen/spacing_middle"
                    android:src="@drawable/ic_icon"
                    android:tint="@color/grey_hard" />

                <TextView
                    android:id="@+id/reportchillspot"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0"
                    android:ellipsize="end"
                    android:gravity="center"
                    android:singleLine="true"
                    android:text="Report"
                    android:textColor="@color/material_grey_800"
                    android:textSize="12sp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/linearLayout6"
                android:layout_width=".0dp"
                android:layout_height="fill_parent"
                android:layout_weight=".2"
                android:background="?attr/selectableItemBackground"
                android:clickable="true"
                android:gravity="center_horizontal"
                android:onClick="clickLayout"
                android:orientation="vertical"
                android:paddingLeft="5dp"
                android:paddingRight="5dp">


                <ImageView
                    android:layout_width="@dimen/spacing_mlarge"
                    android:layout_height="@dimen/spacing_mlarge"
                    android:layout_margin="@dimen/spacing_middle"
                    android:src="@drawable/ic_icon"
                    android:tint="@color/grey_hard" />

                <TextView
                    android:id="@+id/rate_chillspot"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0"
                    android:ellipsize="end"
                    android:gravity="center"
                    android:singleLine="true"
                    android:text="Rate"
                    android:textColor="@color/material_grey_800"
                    android:textSize="12sp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/linearLayout7"
                android:layout_width=".0dp"
                android:layout_height="fill_parent"
                android:layout_weight=".2"
                android:background="?attr/selectableItemBackground"
                android:clickable="true"
                android:gravity="center_horizontal"
                android:onClick="clickLayout"
                android:orientation="vertical"
                android:paddingLeft="5dp"
                android:paddingRight="5dp">


                <ImageView
                    android:layout_width="@dimen/spacing_mlarge"
                    android:layout_height="@dimen/spacing_mlarge"
                    android:layout_margin="@dimen/spacing_middle"
                    android:src="@drawable/ic_icon"
                    android:tint="@color/grey_hard" />

                <TextView
                    android:id="@+id/future_distance"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0"
                    android:ellipsize="end"
                    android:gravity="center"
                    android:singleLine="true"
                    android:text="WorkOmg"
                    android:textColor="@color/material_grey_800"
                    android:textSize="12sp" />
            </LinearLayout>
        </LinearLayout>
    </android.support.v7.widget.CardView>

</LinearLayout>