更多的细节,你可能想创建代码对角线梯度。这很容易,你有很多选择从那里打开。这个片段让我
public void SetGradient(View view) {
GradientDrawable gd = new GradientDrawable(
GradientDrawable.Orientation.TL_BR,
new int[]{0xFF141a24, 0xFF293f49, 0xFF72554c});
view.setBackground(gd);
}
可用方向从GradientDrawable类
/*public enum Orientation {
*//** draw the gradient from the top to the bottom *//*
TOP_BOTTOM,
*//** draw the gradient from the top-right to the bottom-left *//*
TR_BL,
*//** draw the gradient from the right to the left *//*
RIGHT_LEFT,
*//** draw the gradient from the bottom-right to the top-left *//*
BR_TL,
*//** draw the gradient from the bottom to the top *//*
BOTTOM_TOP,
*//** draw the gradient from the bottom-left to the top-right *//*
BL_TR,
*//** draw the gradient from the left to the right *//*
LEFT_RIGHT,
*//** draw the gradient from the top-left to the bottom-right *//*
TL_BR,
}*/
,并调用从的onCreate或onCreateView在片段的方法,并通过父视图(对我来说)。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_view_parent, container);
...
SetGradient(view);
return view;
}
谢谢回答卡恩,但有一件事我发现我可以给角属性的45只倍数,比它崩溃即其他20,20,50等 –
方法有很多种,其中梯度可表达。这里我们实际上是使用线性梯度(沿着直线斜率m =(y-y1)/(x-x1))的斜率。当它是45的倍数时,x和y的变化是相同的。可能是这个原因的原因。我不太了解。 – karn
极好地使用插图解释这个! – Ralphleon