How to create a design in android

I want to create a layout like. for example: when the user clicks a button and then shows an inscription above it to show stickers.

please see this picture, also understand my meaning:

enter image description here

Can you help me?

+4
source share
3 answers

you need to keep the hidden linear layout above your layout, like a button, for example, and make it visible when it is clicked.

This hidden layout will contain your stickers:

example:

Layout

will look something like this:

<LinearLayout
    android:id="@+id/buttonContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:visibility="gone"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/option1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_weight="1"
        android:scaleType="fitCenter"
        android:src="@drawable/image1" />

    <ImageView
        android:id="@+id/option2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_weight="1"
        android:scaleType="fitCenter"
        android:src="@drawable/image2" />

    <ImageView
        android:id="@+id/option3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_weight="1"
        android:scaleType="fitCenter"
        android:src="@drawable/image3" />
</LinearLayout>

place it on top of the layout for the button, customize it according to your needs

and when you click on your button, you should make it visible as follows:

findViewById(R.id.buttonContainer).setVisibility(View.VISIBLE);

, :

 findViewById(R.id.buttonContainer).setVisibility(View.GONE);

, .

+3

,

,

,

+3

.

, .

, .

, :

lytMenu.setX(x, likeButton.getY() - lytMenu.getHeight());

If you do this, your menu layout will overlap other content as a menu when you see it. Otherwise, it will resize your main file.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.sampleforstack.MainActivity" >

    <!--This is your main layout. Add your content here -->
    <LinearLayout 
        android:id="@+id/lytMain"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/accent_material_dark">

    </LinearLayout>
    <!--This is your menu layout. Add smile buttons here -->
    <LinerLayout
        android:id="@+id/lytMenu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone">
    </LinerLayout>

</RelativeLayout>
+1
source

Source: https://habr.com/ru/post/1611155/


All Articles