【问题标题】:How to make custom buttons in corona, Lua如何在电晕,Lua中制作自定义按钮
【发布时间】:2017-07-09 03:25:29
【问题描述】:

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

我正在使用 Corona 制作这个,它是用 Lua 语言编写的

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

【问题讨论】:

    标签: button lua coronasdk


    【解决方案1】:

    使用自定义视图

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

    和值/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"/>
    

    【讨论】:

    • 对不起,我的问题好像没有说清楚。我没有使用 java 或 android studio,我使用的是带有 Corona 的 Lua,真的很抱歉
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2017-03-19
      • 2010-11-23
      • 1970-01-01
      • 1970-01-01
      • 2022-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多