0

How to have flexible post creation feature in an app like the way we have them in social media apps like twitter to enables to add a text ,image,location freely without adding them at the same time .

Post Activity Example

I created a post using EditText for text and ImageView for the image, but in the Android app, I would like to use posts that are not reliant on them.

The post activity will help me add geological discoveries from the field, which will include:

-a title : text -an image : uri,string -date(auto generated ): number -gps coordinates (auto generated): number -dimensions ,auto generated : number -texture , color,hardnes :strings -mineral composition : a text,long a little -structural features :long text -formation ,a text -context : medium text -Name : the name of the rock , it is a text

I want to build something that is user friendly.

Now my XML code is like this :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#000000">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="16dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp">

            <ImageButton
                android:id="@+id/btn_close"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:contentDescription="Close"
                android:src="@android:drawable/ic_menu_close_clear_cancel" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="Drafts"
                android:textColor="#FFFFFF"
                android:textSize="18sp" />

            <Button
                android:id="@+id/btn_post"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_centerVertical="true"
                android:background="@drawable/rounded_button"
                android:text="Post"
                android:textColor="#FFFFFF" />
        </RelativeLayout>

        <com.google.android.material.imageview.ShapeableImageView
            android:id="@+id/profileImage"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:scaleType="centerCrop"
            app:shapeAppearanceOverlay="@style/CircularImageView"
            app:strokeColor="#713808"
            app:strokeWidth="2dp" />

        <EditText
            android:id="@+id/et_post_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:background="@null"
            android:hint="Your discovery"
            android:textColor="#FFFFFF"
            android:textColorHint="#AAAAAA"
            android:minHeight="48dp"
            android:inputType="textMultiLine" />

        <EditText
            android:id="@+id/color"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:hint="Color"
            android:textColor="#FFFFFF"
            android:textColorHint="#AAAAAA"
            android:minHeight="48dp"
            android:inputType="text" />

        <EditText
            android:id="@+id/hardness"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:hint="Hardness"
            android:textColor="#FFFFFF"
            android:textColorHint="#AAAAAA"
            android:minHeight="48dp"
            android:inputType="text" />

        <EditText
            android:id="@+id/composition"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:hint="Composition"
            android:minHeight="48dp"
            android:textColor="#FFFFFF"
            android:textColorHint="#AAAAAA"
            android:inputType="text" />

        <EditText
            android:id="@+id/structuralFeatures"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:hint="Structural features"
            android:textColor="#FFFFFF"
            android:textColorHint="#AAAAAA"
            android:minHeight="48dp"
            android:inputType="text" />

        <EditText
            android:id="@+id/formation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:hint="Formation"
            android:minHeight="48dp"
            android:textColor="#FFFFFF"
            android:textColorHint="#AAAAAA"
            android:inputType="text" />

        <EditText
            android:id="@+id/context"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:hint="Context"
            android:textColor="#FFFFFF"
            android:textColorHint="#AAAAAA"
            android:minHeight="48dp"
            android:inputType="text" />

        <EditText
            android:id="@+id/name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:hint="Name"
            android:textColor="#FFFFFF"
            android:textColorHint="#AAAAAA"
            android:minHeight="48dp"
            android:inputType="text" />

        <EditText
            android:id="@+id/story"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:background="@null"
            android:hint="About?"
            android:textColor="#FFFFFF"
            android:textColorHint="#AAAAAA"
            android:minHeight="48dp"
            android:inputType="textMultiLine" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:padding="16dp">

        <ImageButton
            android:id="@+id/addImage"
            android:layout_width="0dp"
            android:layout_height="48dp"
            android:layout_weight="1"

            android:contentDescription="Add Image"
            android:src="@android:drawable/ic_menu_gallery" />

        <ImageButton
            android:id="@+id/btn_add_gif"
            android:layout_width="0dp"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:contentDescription="Add GIF"
            android:src="@android:drawable/ic_menu_rotate" />

        <ImageButton
            android:id="@+id/btn_add_poll"
            android:layout_width="0dp"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:contentDescription="Add Poll"
            android:src="@android:drawable/ic_menu_sort_by_size" />

        <ImageButton
            android:id="@+id/btn_add_location"
            android:layout_width="0dp"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:contentDescription="Add Location"
            android:src="@android:drawable/ic_menu_mylocation" />

        <ImageButton
            android:id="@+id/btn_more_options"
            android:layout_width="0dp"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:contentDescription="More Options"
            android:src="@android:drawable/ic_menu_more" />
    </LinearLayout>
</RelativeLayout>

1 Answer 1

0

You could try adding the views dynamically.

https://www.youtube.com/watch?v=6IMYGpwuW1I

or just manipulate the visibility of the views.

android:visibility = "Gone" view.setVisibility = View.GONE.

4
  • Hey, Thank you for answering but the youtube video show how to add items in a recyclerView when a button is clicked but i needed a way to have a posting activity like we have for social media apps
    – BALMA
    Commented Nov 26 at 15:23
  • @BALMA Do you mean a popup window with those views?
    – jay chen
    Commented Nov 27 at 3:13
  • I mean the activity similar to what appears in social media apps (Twitter, Facebook, etc.) when you click the Post button, allowing users to add content for posting. In the XML code I shared, I only used an EditText for text input, which is not user-friendly. I want to improve this to allow adding text, images, and videos seamlessly. Please share relevant solutions.
    – BALMA
    Commented Nov 28 at 0:36
  • oh, so it's still the adding views dynamically issue. Try these answers. Adding ImageView to the Layout programmatically
    – jay chen
    Commented Nov 28 at 2:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.