0
votes

I'm trying to make a mobile application with a screen that looks like this:

App mockup

I'm making this using Corona, it's written in the Lua language

It's a scrollable list of buttons, I somewhat understand the scroll aspect. What I'm having problems now is making a button that can have more than one line of text and also an image. I've literally been searching for hour but haven't found anything (I'm probably bad at finding things). I think I'd have to create a custom button but I have no idea how to do this. I would appreciate some help with this be it a link or just some lines of text explaining it, thank you so much!

3

3 Answers

0
votes

use custom view

custom_button_view.xml

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


    <ImageView
        android:id="@+id/iconImgV"
        android:layout_alignParentRight="true"
        android:layout_width="100dp"
        android:layout_alignParentTop="true"
        android:background="#ff0000"
        android:layout_height="100dp" />

    <TextView
        android:id="@+id/titleTv"
        android:textSize="18sp"
        android:text="Title"
        android:layout_toLeftOf="@+id/iconImgV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/descriptionTv"
        android:layout_width="wrap_content"
        android:text="description"
        android:textSize="14sp"
        android:layout_below="@+id/titleTv"
        android:layout_toLeftOf="@+id/iconImgV"
        android:layout_height="wrap_content" />
</RelativeLayout>

and CustomButtonView.java

public class CustomButtonView extends RelativeLayout {

    Context context;

    //view
    ImageView iconImgV;
    TextView titleTv, descriptionTv;


    //value
    int drawableIcon;
    String title,description;


    public CustomButtonView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.context = context;
        init();
    }

    public CustomButtonView(Context context) {
        super(context);
        init();
    }

    public CustomButtonView(Context context, AttributeSet attrs) {
        super(context, attrs);

        this.context = context;
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.customButtonViewAttrs);
        drawableIcon = typedArray.getInt(R.styleable.customButtonViewAttrs_drawableIcon,0);
        title = typedArray.getString(R.styleable.customButtonViewAttrs_title);
        description = typedArray.getString(R.styleable.customButtonViewAttrs_description);
        typedArray.recycle();

        init();
    }

    public void init() {

        if (isInEditMode())
            return;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View myView = inflater.inflate(R.layout.custom_button_view, null);

        iconImgV = (ImageView) myView.findViewById(R.id.iconImgV);
        titleTv = (TextView) myView.findViewById(R.id.titleTv);
        descriptionTv = (TextView) myView.findViewById(R.id.descriptionTv);


        titleTv.setText(title);

        addView(myView);
    }
}

and value/attrs.xml

<declare-styleable name="customButtonViewAttrs">
    <attr name="title" format="string" />
    <attr name="description" format="string" />
    <attr name="drawableIcon" format="integer" />
</declare-styleable>

you can use this way

<com.example.rasoul.testprojectstacj.CustomButtonView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:title = "Car"/>
0
votes

Found a solution, widget.newTable does this perfectly

-1
votes

You can use RecyclerView here.

And it's each item will be the type of layout you want.

Refer this link for info.

https://guides.codepath.com/android/using-the-recyclerview