Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.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_Button_Android Studio - Fatal编程技术网

Java 按钮中的图像模糊,按钮忽略设置大小

Java 按钮中的图像模糊,按钮忽略设置大小,java,android,button,android-studio,Java,Android,Button,Android Studio,在android应用程序中创建按钮有两个问题 按钮(经典按钮)中的图像模糊。我认为Android studio会增加图像的大小,但不确定是否会增加。以下是emulator的屏幕和使用的图像: 有没有办法消除这种模糊效果 在创建按钮的过程中,我设置了按钮的高度,但当按钮内部有图标时(甚至maxSize),它似乎忽略了这一点。 如何设置按钮的大小 这是创建按钮的代码 LinearLayout layout = (LinearLayout) findViewById(R.id.line

在android应用程序中创建按钮有两个问题

  • 按钮(经典
    按钮
    )中的图像模糊。我认为Android studio会增加图像的大小,但不确定是否会增加。以下是emulator的屏幕和使用的图像:
  • 有没有办法消除这种模糊效果

  • 在创建按钮的过程中,我设置了按钮的高度,但当按钮内部有图标时(甚至
    maxSize
    ),它似乎忽略了这一点。 如何设置按钮的大小
  • 这是创建按钮的代码

           LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
            Button button;
            for(Subreddit s:subreddits)
            {
                button = new Button(this);
    
                Drawable img = getResources().getDrawable(R.drawable.reddit2);
                //img.setBounds(0, 0, 50, 60);
                button.setCompoundDrawablesWithIntrinsicBounds(img, null, null, null);
    
                button.setMinHeight(0);
                button.setHeight(30);
                button.setText(s.getDisplayName());
                button.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_shape2));
                button.setTextColor(getResources().getColor(R.color.button_text_color));
                button.setGravity(Gravity.LEFT);
                button.setGravity(Gravity.CENTER_VERTICAL);
                button.setAllCaps(false);
                button.setCompoundDrawablePadding(15);
                button.setMaxHeight(35);
    
                layout.addView(button);
            }
            layout.invalidate();
    
    与setImageResource一起使用。 另外,我会使用RecyclerView或ListView,而不是那样构建它。 无需调用invalidate,一旦将视图添加到视图组中,它就会调用invalidate。无效是一种昂贵的方法。

    与setImageResource一起使用。 另外,我会使用RecyclerView或ListView,而不是那样构建它。 无需调用invalidate,一旦将视图添加到视图组中,它就会调用invalidate。无效化是一种昂贵的方法