Android 折叠工具栏布局和浮动操作按钮在折叠工具栏布局中的位置
我指的是目前我的设计要求略有不同 类似这样的内容(忽略图片和名称下面的部分) 我想浮动的行动按钮在右下角的圆形图像和它下面的人的名字(这将是折叠工具栏布局标题) 到目前为止,我能够做到这一点- 此布局中的问题是,我无法下拉图片下方的标题,也无法重新定位浮动操作按钮 这是我正在使用的布局(从cheesesquare应用程序稍微修改)Android 折叠工具栏布局和浮动操作按钮在折叠工具栏布局中的位置,android,material-design,android-support-library,android-collapsingtoolbarlayout,Android,Material Design,Android Support Library,Android Collapsingtoolbarlayout,我指的是目前我的设计要求略有不同 类似这样的内容(忽略图片和名称下面的部分) 我想浮动的行动按钮在右下角的圆形图像和它下面的人的名字(这将是折叠工具栏布局标题) 到目前为止,我能够做到这一点- 此布局中的问题是,我无法下拉图片下方的标题,也无法重新定位浮动操作按钮 这是我正在使用的布局(从cheesesquare应用程序稍微修改) 您遇到的问题是,CircleImageView是方形框内的一个圆,当您将FAB设置为锚定到CircleImageView时,它锚定到边界框的一角,而不是实际的Im
您遇到的问题是,CircleImageView是方形框内的一个圆,当您将FAB设置为锚定到CircleImageView时,它锚定到边界框的一角,而不是实际的ImageView本身
通常,您可以通过在右侧和底部添加边距来纠正此问题,以将晶圆厂移动到位,但似乎设计支持库中存在一个缺陷,导致忽略边距
下面是另一个进一步的讨论
这是一个已经被谷歌登录的网站
该问题已分配给Android团队中的某个人,希望在以后的版本中得到解决。问题1。在折叠相关视图时隐藏锚定视图
正如我所注意到的,锚属性确实对视图在崩溃时被隐藏的可能性有一些奇怪的影响。因此,久经考验的解决方案是以编程方式执行:
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
/**
* verticalOffset changes in diapason
* from 0 - appBar is fully unwrapped
* to -appBarLayout's height - appBar is totally collapsed
* so in example we hide FAB when user folds half of the appBarLayout
*/
if (appBarLayout.getHeight() / 2 < -verticalOffset) {
fab.setVisibility(View.GONE);
} else {
fab.setVisibility(View.VISIBLE);
}
}
});
并在declare styleable中为其声明附加属性:
<declare-styleable name="FabLayout">
<attr name="anchor_diameter" format="integer" />
</declare-styleable>
在此之后,我们可以替换此:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="53dp"
android:paddingRight="53dp"
...
从何处获取圆形图像视图?我将尝试创建布局,但我需要图像视图。编辑:我现在意识到,CheeseSquare正在使用“感谢”来完成以下步骤:-)
public class CustomFrameLayout extends FrameLayout {
public CustomFrameLayout(Context context) {
super(context);
}
public CustomFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
setupPaddings(context, attrs);
}
public CustomFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setupPaddings(context, attrs);
}
private void setupPaddings(Context context, AttributeSet attrs) {
int diameter = 0;
TypedArray attrArray = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.FabLayout,
0, 0);
try {
diameter = attrArray.getInteger(R.styleable.FabLayout_anchor_diameter, 0);
} finally {
attrArray.recycle();
}
int padding = (int) Math.round((double) diameter * (1d - 1d / (Math.sqrt(2d)))); // in dips
int paddingPx = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, padding, getResources().getDisplayMetrics()));
String xmlAnchorGravity = attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "layout_anchorGravity");
int gravity = Integer.parseInt(xmlAnchorGravity.substring(2), 16);
int top = ((gravity & 0x30) == 0x30) ? 1 : 0;
int bottom = ((gravity & 0x50) == 0x50) ? 1 : 0;
int left = ((gravity & 0x03) == 0x03) ? 1 : 0;
int right = ((gravity & 0x05) == 0x05) ? 1 : 0;
setPadding(left * paddingPx,
top * paddingPx,
right * paddingPx,
bottom * paddingPx);
}
}
<declare-styleable name="FabLayout">
<attr name="anchor_diameter" format="integer" />
</declare-styleable>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="53dp"
android:paddingRight="53dp"
...
<com.example.CustomFrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:anchor_diameter="180"
...