如何在不改变高度的情况下改变矩形的宽度

时间:2016-05-09 17:59:35

标签: java android xml drawable shape

我正在尝试制作一个包含5列的动态条形图,这些列会根据用户输入而变化。我定义了一个矩形xml可绘制形状,如下所示:

Using colorator 0.1
Using ffi 1.9.10
Using sass 3.4.22
Using jekyll-sass-converter 1.4.0
Using rb-fsevent 0.9.7
Using rb-inotify 0.9.7
Using listen 3.0.7
Using jekyll-watch 1.4.0
Using kramdown 1.11.1
Using liquid 3.0.6
Using mercenary 0.3.6
Using rouge 1.10.1
Using safe_yaml 1.0.4
Using jekyll 3.1.3
Using jekyll-sitemap 0.10.0
Using bundler 1.10.6
Bundle complete! 3 Gemfile dependencies, 16 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

我在我的xml布局文件中嵌入了5次条形图,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="rectangle">

<corners
    android:radius="2dp"
    />
<solid
    android:color="#c73434"
    />
<padding
    android:left="0dp"
    android:top="0dp"
    android:right="0dp"
    android:bottom="0dp"
    />
<size
    android:width="270dp"
    android:height="60dp"
    />

<stroke android:width="2px"
        color="#ff00ffff" />
</shape>

我希望能够根据用户输入更改条形的宽度,但是当我调整ImageView的“width”属性时,它也会按比例影响高度(因此整个条形变小)。有什么建议?有没有更好的方法呢?

1 个答案:

答案 0 :(得分:2)

我认为有两件事:

  1. 使用ImageView包装内容而不是match_parent(不确定)
  2. 最重要的是,从您正在使用的背景中删除尺寸限制。我认为它保留了你的宽高比。
相关问题