In android custom_toast_layout layout layout doesn't work

I use a custom toast and in it I provide layout_margin correctly, but it doesn’t work for a single sentence, where is the problem. Below is the code I'm using.

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_toast_layout_id"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFF"
android:orientation="horizontal"
android:layout_marginRight="200dip">

<ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_marginRight="5dp" />

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:textColor="#000" />
</LinearLayout>
0
source share
2 answers

You cannot set a marker on the right on the top partet while its parent fills.

I think you want something like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_toast_layout_id"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFF"
android:orientation="horizontal">

<ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_marginRight="5dp" />

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
android:layout_marginRight="200dip"
    android:textColor="#000" />
</LinearLayout>
0
source

Just place your layout inside another layout as shown below. and set the background to transparent.

<?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="match_parent"
    android:background="@android:color/transparent"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="62dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:padding="2dp"
        android:background="@drawable/bg_round_corner_toast"
        android:orientation="horizontal">
        <ImageView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:src="@drawable/ic_gcm_notification"
            android:scaleType="fitCenter"
            android:layout_margin="10dp"
            android:layout_gravity="center_vertical"
            android:layout_weight="2"/>
        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="8">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="ixprez"
                android:textStyle="italic"
                android:textSize="12sp"
                android:id="@+id/tv_toast_title"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:text="Messsage "
                android:layout_margin="1dp"
                android:maxLines="3"
                android:gravity="top"
                android:layout_gravity="left|top"
                android:textSize="14sp"
                android:textStyle="normal"
                android:textAlignment="center"
                android:textColor="@color/white"
                android:id="@+id/tv_toast_msg"
                android:layout_below="@+id/tv_toast_title"
                />

        </RelativeLayout>

    </LinearLayout>


</LinearLayout>
0
source

All Articles