【问题标题】:Circle shape height and width issues in xmlxml中的圆形高度和宽度问题
【发布时间】:2014-08-25 08:09:25
【问题描述】:

我创建了一个椭圆形并将每个高度和宽度的大小设置为 56 像素。但我有一个椭圆形而不是圆形!当我将每个尺寸设置为 78 像素时,我得到了一个精确的圆圈!有人注意到或遇到过这个问题吗? 请解决!

clear_test.xml 这给了我一个椭圆形的形状!布局中不同的高度和宽度

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#7caf00"/>
    <size android:width="56px"
        android:height="56px"/>

</shape>

calc_test.xml 但这给出了一个精确的圆圈

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#7caf00"/>
    <size android:width="78px"
        android:height="78px"/>



</shape>

【问题讨论】:

  • 邮政编码了解更多信息。

标签: android android-layout android-xml android-shape


【解决方案1】:

形状取决于您的视图的大小。您设置此形状可绘制的视图应该具有相同的大小

例如:

<view android:layout_width="56px" android:layout_height="56px" android:background="@drawable/clear_test"/>

注意: 你不应该使用 px,总是使用 dp/dip 作为测量单位。(上面的例子有“px”,所以它确实匹配你的 xml 代码)

【讨论】:

  • 它工作正常!但我支持多个屏幕,所以我需要更大的形状来获得更大的屏幕!我设置了高度和宽度wrap_content。为什么当尺寸为 78px 时它会起作用!奇怪..
  • 你用的是什么视图,imageview,textview?
  • 既然要支持多屏,最好通过代码设置view的大小,因为wrap_content可能会给出矩形而不是方形
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-24
  • 2013-04-28
  • 1970-01-01
  • 2012-08-07
相关资源
最近更新 更多