更多的細節,你可能想創建代碼對角線梯度。這很容易,你有很多選擇從那裏打開。這個片段讓我
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