このFrameLayout
を取ります影を描くとthis gradient drawable xml:
public class DrawShadowFrameLayout extends FrameLayout {
private Drawable mShadowDrawable;
private final int mShadowElevation = 8;
private int mWidth;
private int mHeight;
private boolean mShadowVisible = true;
public DrawShadowFrameLayout(Context context) {
this(context, null, 0);
init();
}
public DrawShadowFrameLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
init();
}
public DrawShadowFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
mShadowDrawable = ContextCompat.getDrawable(getContext(), R.drawable.shadow);
if (mShadowDrawable != null) {
mShadowDrawable.setCallback(this);
}
setWillNotDraw(!mShadowVisible);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mWidth = w;
mHeight = h;
updateShadowBounds();
}
private void updateShadowBounds() {
if (mShadowDrawable != null) {
mShadowDrawable.setBounds(0, 0, mWidth, mShadowElevation);
}
ViewCompat.postInvalidateOnAnimation(this);
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
if (mShadowDrawable != null && mShadowVisible) {
getBackground().setBounds(0, mShadowDrawable.getBounds().bottom, mWidth, mHeight);
mShadowDrawable.draw(canvas);
}
}
public void setShadowVisible(boolean shadowVisible) {
setWillNotDraw(!mShadowVisible);
updateShadowBounds();
}
int getShadowElevation() {
return mShadowVisible ? mShadowElevation : 0;
}
}
のように、この中にあなたBottomNavigationView
このレイアウトをラップ:残念ながら、ネイティブの影がビューの下に描かれている
<DrawShadowFrameLayout>
<BottomNavigationView />
</DrawShadowFrameLayout>
、我々はこの上向きの影に自分自身を模倣する必要があります。
DrawShadowFrameLayout
もandroid:elevation="8dp"
を追加しないでください。
Another approach is extendingBottomNavigationView
そしてこれを上書きするdraw()
。これは、あなたのビュー階層内でFrameLayout
を緩めるのに役立ちます。
それは背景が白の場合にのみ影が表示されていることは事実です。それは愚かです。どんな考え? – WindRider
私はそれが非常に不満であり、なぜか手掛かりを持っていないことに同意します。 – luksha
こんにちは@luksha私はまさにあなたの言うことをしていますが、私はまだ働いていません:(驚くべきことに、画面の上にBottomNavigationBarを置くと、ナビゲーションビューの下端を上げます。スクリーン、標高が機能しなくなる –