繁体   English   中英

设置图像时操作栏标题消失

[英]Action Bar Title Disappearing When Setting Image

我正在尝试将图像设置到操作栏中,我正在使用CircularImagView来做到这一点。

(ScaleType.FIT_END不适用于CircularImageView,但即使应用了ScaleType.FIT_END,我也尝试了ImageView相同的结果)。

它适用于大屏幕手机,但标题不适合宽屏幕手机。

例如标题对于像nexas 5x这样的宽手机来说效果很好

连结5倍

但是不会出现在像我的实体电话这样的狭窄设备中。

并排比较

这是我用来设置图像的代码

             try {
                // setting the image in the actionbar
                getSupportActionBar().setDisplayOptions(getSupportActionBar().getDisplayOptions()
                        | ActionBar.DISPLAY_SHOW_CUSTOM);
                CircleImageView imageView = new CircleImageView(getSupportActionBar().getThemedContext());
                //imageView.setScaleType(CircleImageView.ScaleType.FIT_END);
                //imageView.setForegroundGravity(Gravity.RIGHT);
                imageView.setImageBitmap(bitmap);
                getSupportActionBar().setCustomView(imageView);
                // setting the image in actionbar ends here
            } catch (Exception e) {
                e.printStackTrace();
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }

甚至ScaleType.FIT_END或Gravity.RIGHT也无济于事

(ScaleType.FIT_END不适用于CircularImageView,但即使应用了ScaleType.FIT_END,我也尝试了ImageView相同的结果)。

位图是全局变量,我在onCreate中进行了设置,为了使事情复杂一些,我没有添加它。

这可能是什么解决方案?

根据Manohar Reddy的建议,我创建了LinearLayout来创建LayoutParam,在其上设置了宽度和高度,并将该布局参数设置为imageview,从而解决了该问题

    try {
                    // setting the image in the actionbar
                    getSupportActionBar().setDisplayOptions(getSupportActionBar().getDisplayOptions()
                            | ActionBar.DISPLAY_SHOW_CUSTOM);
                    CircleImageView imageView = new CircleImageView(getSupportActionBar().getThemedContext());

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(70, 70);
                    imageView.setLayoutParams(layoutParams);
                    imageView.setImageBitmap(bitmap);
                    getSupportActionBar().setCustomView(imageView);
                    // setting the image in actionbar ends here
     } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
                }

必须创建一个新的布局参数,导致活动xml中没有imageview,因此无法获取该参数。 希望这对某人有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM