如何使imageView采取relativelayout的匹配父

时间:2017-10-24 18:59:55

标签: android android-imageview gif android-relativelayout

我正在尝试const getRarest = originalArray => { const temp = {}; const counts = originalArray .map(item => { temp[item] = 0; return item; }) .reduce((acc, item) => { acc[item]++; return acc; }, temp); const resultArray = Object.entries(counts).sort( ([key, val], [bKey, bVal]) => bVal < val ); return (rarest = parseInt(resultArray[0][0])); }; //Implementation const arr = [3, 2, 4, 4]; console.log(getRarest(arr)); ImageView match_parent 喜欢这张图片:

enter image description here

当我运行我的应用时RelativeLayout看起来像这样:

enter image description here

这是我的xml:

ImageView

3 个答案:

答案 0 :(得分:3)

将ImageView的layout_width更改为match_parent,并为其添加一个新属性:android:adjustViewBounds="true"

答案 1 :(得分:3)

如果您想要符合ImageView width,那么您必须忽略height。并且默认情况下不会拉伸以保持纵横比,因此您需要为调整视图边界添加其他属性。最后,对于ImageView

,您将获得如下代码字符
 android:layout_width="match_parent"
 android:adjustViewBounds="true"

调整视图边界将调整到特定高度,同时保持纵横比。

更多

另外,为了避免以后在代码中再次出现错误,您已经嵌套了两个RelativeLayout,我认为这是应有的背景。如果没有必要,如果不关心空间。内部RelativeLayout视图heightwidth应设置为match_parent快乐编码!

答案 2 :(得分:2)

您的/* Used to generate and encapsulate pairwise independent hash functions. See see https://people.csail.mit.edu/ronitt/COURSE/S12/handouts/lec5.pdf , claim 5 for more information. */ private static class HashF { private final int a; private final int b; private final int p = 1610612741; // prime HashF(int a, int b) { Random rand = new Random(); this.a = rand.nextInt(p); this.b = rand.nextInt(p); } // hashes integers public int hash(int x) { return (a*x + b) % p; } } ImageViewlayout_width设置为layout_height而不是wrap_content