相关疑难解决方法(0)

我什么时候可以先测量视图?

所以我在尝试设置视图的背景可绘制时有点混乱.该代码依赖于知道视线的高度,所以我不能把它onCreate()onResume(),因为getHeight()返回0 onResume()似乎是最接近我可以得到虽然.我应该在哪里放置如下所示的代码,以便在显示给用户时背景发生变化?

    TextView tv = (TextView)findViewById(R.id.image_test);
    LayerDrawable ld = (LayerDrawable)tv.getBackground();
    int height = tv.getHeight(); //when to call this so as not to get 0?
    int topInset = height / 2;
    ld.setLayerInset(1, 0, topInset, 0, 0);
    tv.setBackgroundDrawable(ld);
Run Code Online (Sandbox Code Playgroud)

height layout android android-lifecycle

59
推荐指数
3
解决办法
5万
查看次数

标签 统计

android ×1

android-lifecycle ×1

height ×1

layout ×1