【问题标题】:Icon or image in actionbar操作栏中的图标或图像
【发布时间】:2014-07-21 18:29:53
【问题描述】:

我需要在动作栏中制作图标(图像视图),该图标(图像视图)在动作栏中显示一半图像,另一半显示在屏幕(布局)中,如下图所示:

一个想法是在颜色下方具有透明的图像,但是当我为操作栏设置背景时,图像变形,如果我使操作栏高度,布局尺寸会变小

现在我应该怎么做才能解决这个问题?

【问题讨论】:

    标签: android android-layout android-actionbar


    【解决方案1】:

    据我所知,您无法将View 添加到ActionBar 并实现此目的,因为视图不能超出其父(容器)的限制 - 在本例中为 ActionBar。您可以做的一件事是将此ImageView 添加到装饰视图,它是ActionBar 和Activity (Fragment) 布局的父级。示例(来自您的 Activity,例如在 onPostCreate() 中):

    ViewGroup decor = (ViewGroup) getWindow().getDecorView();
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View customLayout = inflater.inflate(R.layout.my_layout, null);
    // find views in customLayout, add click listeners etc.
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    // add margins, gravity, etc. to this LayoutParams
    decor.addView(imageView, params);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多