może chcesz stworzyć przekątnej gradient od kodu. To znacznie łatwiejsze i masz wiele otwartych opcji. Ten fragment pomógł mi
public void SetGradient(View view) {
GradientDrawable gd = new GradientDrawable(
GradientDrawable.Orientation.TL_BR,
new int[]{0xFF141a24, 0xFF293f49, 0xFF72554c});
view.setBackground(gd);
}
dostępne kierunki z GradientDrawable klasy
/*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,
}*/
i wywołać metodę z onCreate lub onCreateView fragmentu i przechodzą w widoku nadrzędnego (w moim przypadku).
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_view_parent, container);
...
SetGradient(view);
return view;
}
Dzięki za odpowiedź Karn, ale jedno odkryłem, że mogę dać tylko wielokrotności 45 w atrybucie kątem, inne niż to, że wywala czyli 20, 20, 50 itd –
Istnieje wiele sposobów, w których nachylenie może być wyrażone. Tutaj faktycznie używamy gradientu liniowego (nachylenie wzdłuż nachylenia prostej liniowej m = (y-y1)/(x-x1)). Kiedy jest wielokrotnością 45, wariacja x i y jest taka sama. Może być przyczyną tego powodu. Nie wiem zbyt wiele. – karn
Doskonałe wykorzystanie ilustracji wyjaśniającej to! – Ralphleon