Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 圆形变为椭圆形_Android_Xml_Android Layout_Drawable_Shapes - Fatal编程技术网

Android 圆形变为椭圆形

Android 圆形变为椭圆形,android,xml,android-layout,drawable,shapes,Android,Xml,Android Layout,Drawable,Shapes,我有一个drawable,我想用作textView的背景。drawable在xml中声明为textView后台。我在不同尺寸的屏幕上测试drawable时遇到了一个问题,因为有时候它会向外延伸,变成椭圆形而不是圆形 因此,具体来说,我的问题如下:是否有任何方法可以确保可绘制的始终是一个圆形,而不是延伸成椭圆形?我希望一切都能用XML完成。 我可以发布我的一些代码,但我认为这是不必要的,因为它是一个简单的可绘制文件,使用椭圆形,然后在布局中我将可绘制文件设置为textView的背景。我的尝试是使用

我有一个drawable,我想用作textView的背景。drawable在xml中声明为textView后台。我在不同尺寸的屏幕上测试drawable时遇到了一个问题,因为有时候它会向外延伸,变成椭圆形而不是圆形

因此,具体来说,我的问题如下:是否有任何方法可以确保可绘制的始终是一个圆形,而不是延伸成椭圆形?我希望一切都能用XML完成。

我可以发布我的一些代码,但我认为这是不必要的,因为它是一个简单的可绘制文件,使用椭圆形,然后在布局中我将可绘制文件设置为textView的背景。我的尝试是使用权重和线性布局来绘制圆形,在大多数情况下,它可以工作,但在某些屏幕尺寸下,它仍然会拉伸一点

为完整起见,如果有人感兴趣,请参阅布局代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="6"
    android:text="Button" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="4"
    android:gravity="center_horizontal|bottom"
    android:text="Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
    android:id="@+id/gradientline1"
    android:layout_width="match_parent"
    android:layout_height="2dp"
    android:src="@drawable/gradient_line" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="8"
    android:gravity="center"
    android:text="Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="4"
    android:gravity="center_horizontal|bottom"
    android:text="Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
    android:id="@+id/gradientline2"
    android:layout_width="match_parent"
    android:layout_height="2dp"
    android:src="@drawable/gradient_line" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="24"
    android:orientation="horizontal" >

    <View
        android:layout_width="1dp"
        android:layout_height="0dp"
        android:layout_weight="5" >
    </View>

    <TextView
        android:id="@+id/textView4"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="20"
        android:background="@drawable/circle"
        android:gravity="center"
        android:text="Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <View
        android:layout_width="1dp"
        android:layout_height="0dp"
        android:layout_weight="5" >
    </View>
</LinearLayout>

这是一个可绘制的圆(只是一层层的圆):



将包装内容中的布局宽度和高度放入xml文件中

android:layout_width="wrap_content"
android:layout_height="wrap_content"
使用
shape=“ring”
(非椭圆形)

尝试:



为了做到这一点,我必须为可绘制的圆提供一个单独的视图,对吗?因为如果在textview上使用wrap_内容,那么圆圈将更像一个椭圆形。如果我在单独的视图中使用可绘制的wrap_内容,那么我必须在可绘制的图形中声明形状的大小?如果您有时间查看,我添加了代码。我相信这是一个快速解决方案,但我很难找到它。谢谢你的帮助。你能举例说明你正在努力完成什么吗?
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadius="0dp"
    android:shape="ring"
    android:thicknessRatio="2"
    android:useLevel="false"  >

    <!-- View background color -->
    <solid
        android:color="@color/white" >
    </solid>

    <!-- View border color and width -->
    <stroke
        android:width="1.6dp"
        android:color="@color/beam_grey" >
    </stroke>
</shape>