热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

androidgradientdrawable参数,Android的:如何在层列表中更改GradientDrawable的大小编程...

android:width3dpandroid:colorcolorgray4android:drawabledrawabledot_pattern_bitmap这

android:width="3dp"

android:color="@color/gray4"/>

android:drawable="@drawable/dot_pattern_bitmap"/>

这是在自定义的FrameLayout customView.xml使用:

android:layout_width="match_parent"

android:layout_height="match_parent"

android:src="@drawable/layers"/>

它本身被用于例如在

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:padding="@dimen/space_m"

android:orientation="vertical">

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

此外,我有CustomView.java类来编辑自定义视图(特别是图层)的行为。

在那里,我试图根据customView的大小(和参数'ratio')实现层列表大小的更新。我试过这样:

// ...

@Override

protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {

super.onMeasure(widthMeasureSpec, heightMeasureSpec);

layoutWidth = MeasureSpec.getSize(widthMeasureSpec);

layoutHeight = MeasureSpec.getSize(heightMeasureSpec);

readjustSize(ratio);

}

private void readjustSize(final double ratio) {

if (layoutHeight != 0 && layoutWidth != 0) {

// determine desired width and height using the layout width

int desiredWidth = layoutWidth;

int desiredHeight = (int) (layoutWidth/ratio);

// if it does not fit, adjust using the layout height

if (desiredHeight > layoutHeight) {

desiredHeight = layoutHeight;

desiredWidth = (int) (layoutHeight * ratio);

}

// get the basic layer

final LayerDrawable ld =

(LayerDrawable) ContextCompat.getDrawable(getContext(), R.layers);

final GradientDrawable outerRectShape =

(GradientDrawable) ld.findDrawableByLayerId(R.id.outer_rect);

// and adapt the size

outerRectShape.setSize(desiredWidth, desiredHeight);

outerRectShape.setBounds(0, 0, desiredWidth, desiredHeight);

// redraw

invalidate();

requestLayout();

}

}

所以,那是很多代码...不幸的是,这不能正常工作。如果第一次加载框架布局,我只能看到一个非常小的矩形。

b16433dfb28385b4cd5f939e0ac09a64.png

是否有人有想法:

8d83f58cc7b6e486f84fd4fd74e59c32.png

只有当我来回切换这个观点,因为我想规模应用?

2016-10-18

Caro

+0

将ImageView设置为match_parent的宽度。 –

+0

ImageView本身的宽度上有match_parent。包含视图不会,但我已经尝试了宽度和高度的match_parent,仅限宽度或没有(如发布)。这没有任何改变。 –

+0

在FrameLayout中,它是wrap_content。 –



推荐阅读
author-avatar
景圣南_863
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有