如何在电晕,Lua中制作自定义按钮

时间:2017-07-09 03:25:29

标签: button lua corona

我正在尝试使用如下所示的屏幕制作移动应用程序:

App mockup

我使用Corona制作它,它是用Lua语言编写的

这是一个可滚动的按钮列表,我有点理解滚动方面。我现在遇到的问题是制作一个可以有多行文字和图像的按钮。我一直在寻找小时但却没有找到任何东西(我可能很难找到东西)。我想我必须创建一个自定义按钮,但我不知道如何做到这一点。我希望得到一些帮助,无论是链接还是只是解释它的一些文字,非常感谢你!

3 个答案:

答案 0 :(得分:0)

使用自定义视图

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

和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);
    }
}

和value / attrs.xml

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

你可以这样使用

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

答案 1 :(得分:0)

找到一个解决方案,widget.newTable完美地完成了这个

答案 2 :(得分:-1)

您可以在此处使用RecyclerView。

每个项目都是您想要的布局类型。

请参阅此链接以获取信息。

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