【发布时间】:2015-09-30 11:34:02
【问题描述】:
我正在尝试使用this tutorial 实现具有图像模式的灵活空间。
一切正常。
注意 AppBarLayout 的高度定义为 192dp。
我想改为屏幕的 1/3 高度,以匹配 this google example for the pattern here。
这里是activity的onCreate中的代码(布局xml和教程中的一模一样):
AppBarLayout appbar = (AppBarLayout)findViewById(R.id.appbar);
float density = getResources().getDisplayMetrics().density;
float heightDp = getResources().getDisplayMetrics().heightPixels / density;
appbar.setLayoutParams(new CoordinatorLayout.LayoutParams(LayoutParams.MATCH_PARENT, Math.round(heightDp / 3)));
但由于某种原因,结果不是我所期望的。这段代码我根本看不到应用栏。 (没有代码,高度按预期显示,但它来自 XML,不能动态设置)。
【问题讨论】:
标签: java android android-5.0-lollipop material-design appbar