【问题标题】:Incorrect height of RemoteViews notification when using linear layout使用线性布局时 RemoteViews 通知的高度不正确
【发布时间】:2014-12-28 19:00:24
【问题描述】:

我使用带有自定义布局的 RemoteViews 创建了一个通知。布局结构如下。

<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent" > 
  <ImageView
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:layout_gravity="center"
      android:scaleType="centerCrop"
      android:adjustViewBounds="true" />
  <LinearLayout
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="6"
      android:layout_gravity="center_vertical"
      android:orientation="vertical"
      android:paddingLeft="8dp"
      android:paddingTop="8.0dip" >
  </LinearLayout> 
  <LinearLayout
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="4"
      android:divider="?android:listDivider"
      android:dividerPadding="12.0dip"
      android:gravity="center_vertical"
      android:layout_gravity="center"
      android:orientation="horizontal"
      android:showDividers="middle|beginning" >
  </LinearLayout>
</LinearLayout>

这一切的影响只出现在通知高度的一小部分,而不是通知的整个高度。例如。在http://i57.tinypic.com/14dzo9i.png 处查看截图中的按钮(中间通知是问题的焦点),它们位于父 LinearLayout 的最后一个子项中,并且应该全部垂直居中对齐。

我的问题与Height of notification incorrect "match_parent" 非常相似,但由于那里没有真正的答案,所以我在问这个。该问题的答案确实是指一种动态计算通知高度的方法。如果这是要使用的解决方案,我想知道如何使用从那里获得的高度来动态设置远程视图的高度,因为我没有在远程视图对象上看到高度设置器。

请注意,当我使用相对布局时,图像的高度很好。相对布局仍然有两个问题:1.按钮仍然没有垂直居中对齐;2.我只能包装内容或填充父级,不能将可用空间分成两个子级线性布局。截图:http://i59.tinypic.com/o1000j.png

【问题讨论】:

    标签: android android-layout notifications


    【解决方案1】:

    似乎正在努力将 android:layout_height="wrap_content" 更改为 android:layout_height="match_parent" 以获取内部视图。不知何故之前错过了它,尽管这种值组合的行为很有趣。

    【讨论】:

      【解决方案2】:

      将您的 Layout 更改为 RelativeLayout 并使用参数 android:toLeftOf="@+id/...", android:toRightOf="@+id/..." 在布局中对齐您的 subView。

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity="center_vertical">
      
      <ImageView
          android:id="@+id/image1"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_alignParentLeft="true"
          android:src="@drawable/ic_launcher" />
      <ImageView
          android:id="@+id/image2"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_toRightOf="@+id/image1"
          android:src="@drawable/ic_launcher" />
      </RelativeLayout>
      

      【讨论】:

        猜你喜欢
        • 2021-05-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-07
        • 1970-01-01
        相关资源
        最近更新 更多