【问题标题】:Gravity right circle drawable by using xml使用xml可绘制的重力右圆
【发布时间】:2018-03-04 17:14:53
【问题描述】:

我正在尝试实现 drawable 看起来像这样:

我使用这个 xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:gravity="end">
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval"
        >
        <size
            android:width="@dimen/bullet_size"
            android:height="@dimen/bullet_size"
            />
        <solid android:color="@color/colorPrimary"/>
    </shape>
</item>
</layer-list>

但是得到了这个:

有什么想法可能是错的吗?

我使用的重力右圆可拖动如下:

textView.setBackgroundResources(R.drawable.right_shspe);

【问题讨论】:

  • 你能提供你的布局文件的 XML 吗?您可能使用了带有错误参数的ImageView
  • 我使用 xml drawable 作为背景
  • 请在此处编辑包含您的形状的 XML 布局的问题和代码。
  • 您可以使用 ImageView 并将形状用作其android:src 属性。这样形状纵横比就不会改变并保持您定义的样子。

标签: android xml drawable


【解决方案1】:

我认为您应该将保持椭圆形垂直的项目居中,一切都会好起来的。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:gravity="end|center_vertical">
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval"
        >
        <size
            android:width="@dimen/bullet_size"
            android:height="@dimen/bullet_size"
            />
        <solid android:color="@color/colorPrimary"/>
    </shape>
</item>
</layer-list>

【讨论】:

  • 完成!非常感谢!
【解决方案2】:

相应地更改宽度和高度,它将修复形状

【讨论】:

  • 宽高同值10dp
  • 它可能存在一些问题尝试重新构建您的项目
  • 在我的工作正常。显示一个圆圈 您的项目有问题
  • 检查尺寸文件
  • 10dp
猜你喜欢
  • 2015-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-08
  • 2012-02-08
  • 1970-01-01
相关资源
最近更新 更多