English 中文(简体)
在上下文菜单和机器人上的线条上吗?
原标题:lines on context menu in android?

我正在开发一个需要绘制用户签名的应用程序。 点击一个按钮时, 我需要显示上下文菜单, 用户可以选择要绘制的线厚。 任何人都可以帮助我创建不同线厚的上下文菜单。 也就是说, 我想要一条以厚度高的线作为上下文菜单的第一个项, 以最小厚的线作为上下文菜单的最后一项 。 请帮助我 。

最佳回答

您可以在单击按钮时显示 AwardDialog 而非上下文菜单, 以选择行厚度 。

给例如。

public void lineButtonClick(View v) {
                    Builder builder = new Builder(this);
                    builder.setTitle("Line Thickness");
                    builder.setAdapter(new LineAdapter(this), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // here you get index of clicked item in "which" parameter
                        }
                    });
                    builder.create().show();
                }

                class LineAdapter extends BaseAdapter {
                    // these are the line images with different thickness
                    int lineIds[] = {
                        R.drawable.line1, R.drawable.line2, R.drawable.line3, R.drawable.line4, R.drawable.line5    
                    };

                    @Override
                    public int getCount() {
                        return lineIds.length;
                    }

                    @Override
                    public Object getItem(int arg0) {
                        return arg0;
                    }

                    @Override
                    public long getItemId(int position) {
                        return position;
                    }

                    @Override
                    public View getView(int position, View convertView, ViewGroup parent) {
                        ViewHolder holder;
                        if(convertView == null) {
                            convertView = getLayoutInflater().inflate(R.layout.raw_line, null);
                            holder = new ViewHolder();
                            holder.imgLine = (ImageView)convertView.findViewById(R.id.imgLine);
                            convertView.setTag(holder);
                        } else {
                            holder = (ViewHolder) convertView.getTag();
                        }

                        holder.imgLine.setImageResource(lineIds[position]);
                        return convertView;
                    }

                    class ViewHolder {
                        ImageView imgLine;
                    }
                }

    // raw_line.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/imgLine"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

    </LinearLayout>
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签