mousik mousik - 19 days ago 5
Android Question

Need fit in LinearLayout icons on every device

I hope that atleast someone will try help me :)

I am beginner and sorry for my english.

My problem:
I need to fit this linearlayout on every device and I do not know how (it fits on my phone, but I think it will not fit on the others)

<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

Thank you very much guys for help, I tried my best but I do not know here....

//EDIT:

First of all, thanks for help guys, I really appreciate it.

Here are results: (not working :/ )

click here for screenshots

Answer

Only add android:layout_weight=".2" and changed android:layout_width=".0dp" for each LinearLayout because 0.2 * (5 LinearLayout) is 1 it's your android:weightSum="1"

try this code..

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