Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 调整警报图标的大小_Java_Android_Arraylist_Icons_Android Alertdialog - Fatal编程技术网

Java 调整警报图标的大小

Java 调整警报图标的大小,java,android,arraylist,icons,android-alertdialog,Java,Android,Arraylist,Icons,Android Alertdialog,晚上, 我看到了这篇非常有用的帖子,除了尺码之外,我所有的东西看起来都很好。。。 职位: 有一条关于setBounds的评论,然后调用另一个setCompoundDrawables 这是我的 ... switch(currently_selected){ ... case 3: final Item[] items2 = { new Item("Company 1", R.drawable.c_1),

晚上,

我看到了这篇非常有用的帖子,除了尺码之外,我所有的东西看起来都很好。。。 职位:

有一条关于setBounds的评论,然后调用另一个setCompoundDrawables

这是我的

...
switch(currently_selected){
...
    case 3:

                final Item[] items2 = {
                    new Item("Company 1", R.drawable.c_1),
                    new Item("Company 2", R.drawable.c_2),
                    new Item("Company 3", R.drawable.c_3),
                    new Item("Company 4", R.drawable.c_4),
                    new Item("Company 5", R.drawable.c_5)//no icon for this one
                };

                ListAdapter adapter = new ArrayAdapter<Item>(
                                                MainPortal.this,
                                                android.R.layout.select_dialog_item,
                                                android.R.id.text1,
                                                items2){
                        public View getView(int position, View convertView, ViewGroup parent) {
                            //User super class to create the View
                            View v = super.getView(position, convertView, parent);
                            TextView tv = (TextView)v.findViewById(android.R.id.text1);

                            //Put the image on the TextView

                            tv.setCompoundDrawablesWithIntrinsicBounds(items2[position].icon, 0, 0, 0);

                            //Add margin between image and text (support various screen densities)
                            int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
                            tv.setCompoundDrawablePadding(dp5);

                            return v;
                        }
                    };

                AlertDialog.Builder builder1 = new AlertDialog.Builder(MainPortal.this);
                builder1.setTitle("Please select the Module you wish to load and use");
                builder1.setAdapter(adapter, new DialogInterface.OnClickListener() {
                //builder1.setItems(items1, new DialogInterface.OnClickListener() { // comment out this line to try to use the adapter
                    public void onClick(DialogInterface dialog, int item) {
                        Toast.makeText(getApplicationContext(), items1[item], Toast.LENGTH_LONG).show();
                    }
                }).create().show();

                break;
...
}//end switch
所以这个工作非常好,5-6个小时后我就开始工作了

虽然我对这方面太陌生了,无法理解其中的一些东西是什么。 我的公司1-5,可以选择在名称旁边显示公司标题

如果可能的话,我想在保持长宽比的同时缩小尺寸。 因此,

如果您能以正确的方式设置边界,并提供任何帮助,我将不胜感激。我只是不理解items2[position]。图标是一个整数,并且引用或转换了一个可绘制的图标

谢谢,
约书亚

经过一番挖掘,我终于找到了答案

为了调整大小,所需的更改如下。之后,一个简单的if语句将足以调整公司的横幅大小

final Drawable image;
Resources res = getResources();
image = res.getDrawable(items2[position].icon);
image.setBounds(0, 0, 50, 50);
tv.setCompoundDrawables(image, null, null, null);

//tv.setCompoundDrawablesWithIntrinsicBounds(image,0,0,0);//items2[position].icon, 0, 0, 0);
final Drawable image;
Resources res = getResources();
image = res.getDrawable(items2[position].icon);
image.setBounds(0, 0, 50, 50);
tv.setCompoundDrawables(image, null, null, null);

//tv.setCompoundDrawablesWithIntrinsicBounds(image,0,0,0);//items2[position].icon, 0, 0, 0);