日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

android layout background,Android LinearLayout Gradient Background

發(fā)布時(shí)間:2024/10/8 Android 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android layout background,Android LinearLayout Gradient Background 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

問題

I am having trouble applying a gradient background to a LinearLayout.

This should be relatively simple from what I have read but it just doesn't seem to work. For reference sakes I am developing on 2.1-update1.

header_bg.xml:

android:shape="rectangle">

android:angle="90"

android:startColor="#FFFF0000"

android:endColor="#FF00FF00"

android:type="linear"/>

main_header.xml:

android:layout_width="fill_parent"

android:layout_height="50dip"

android:orientation="horizontal"

android:background="@drawable/header_bg">

If I change @drawable/header_bg to a color - e.g. #FF0000 it works perfectly fine. Am I missing something obvious here?

回答1:

Ok I have managed to solve this using a selector. See code below:

main_header.xml:

android:layout_width="fill_parent"

android:layout_height="50dip"

android:orientation="horizontal"

android:background="@drawable/main_header_selector">

main_header_selector.xml:

android:angle="90"

android:startColor="#FFFF0000"

android:endColor="#FF00FF00"

android:type="linear" />

Hopefully this helps someone who has the same problem.

回答2:

It is also possible to have the third color (center). And different kinds of shapes.

For example in drawable/gradient.xml:

xmlns:android="http://schemas.android.com/apk/res/android"

android:shape="rectangle">

android:startColor="#000000"

android:centerColor="#5b5b5b"

android:endColor="#000000"

android:angle="0" />

This gives you black - gray - black (left to right) which is my favorite dark background atm.

Remember to add gradient.xml as background in your layout xml:

android:background="@drawable/gradient"

It is also possible to rotate, with:

angle="0"

gives you a vertical line

and with

angle="90"

gives you a horizontal line

Possible angles are:

0, 90, 180, 270.

Also there are few different kind of shapes:

android:shape="rectangle"

Rounded shape:

android:shape="oval"

and problably a few more.

Hope it helps, cheers!

回答3:

In XML Drawable File:

android:endColor="#9b0493"

android:startColor="#38068f"

android:type="linear" />

In your layout file: android:background="@drawable/gradient_background"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@drawable/gradient_background"

android:orientation="vertical"

android:padding="20dp">

.....

回答4:

Try removing android:gradientRadius="90". Here is one that works for me:

xmlns:android="http://schemas.android.com/apk/res/android"

android:shape="rectangle"

>

android:startColor="@color/purple"

android:endColor="@color/pink"

android:angle="270" />

回答5:

My problem was the .xml extension was not added to the filename of the newly created XML file. Adding the .xml extension fixed my problem.

回答6:

I don't know if this will help anybody, but my problem was I was trying to set the gradient to the "src" property of an ImageView like so:

android:id="@+id/imgToast"

android:layout_width="wrap_content"

android:layout_height="60dp"

android:src="@drawable/toast_bg"

android:adjustViewBounds="true"

android:scaleType="fitXY"/>

Not 100% sure why that didn't work, but now I changed it and put the drawable in the "background" property of the ImageView's parent, which is a RelativeLayout in my case, like so: (this worked successfully)

android:layout_width="match_parent"

android:id="@+id/custom_toast_layout_id"

android:layout_height="match_parent"

android:background="@drawable/toast_bg">

回答7:

I would check your alpha channel on your gradient colors. For me, when I was testing my code out I had the alpha channel set wrong on the colors and it did not work for me. Once I got the alpha channel set it all worked!

回答8:

You can used a custom view to do that. With this solution, it's finished the gradient shapes of all colors in your projects:

class GradientView(context: Context, attrs: AttributeSet) : View(context, attrs) {

// Properties

private val paint: Paint = Paint()

private val rect = Rect()

//region Attributes

var start: Int = Color.WHITE

var end: Int = Color.WHITE

//endregion

override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {

super.onSizeChanged(w, h, oldw, oldh)

// Update Size

val usableWidth = width - (paddingLeft + paddingRight)

val usableHeight = height - (paddingTop + paddingBottom)

rect.right = usableWidth

rect.bottom = usableHeight

// Update Color

paint.shader = LinearGradient(0f, 0f, width.toFloat(), 0f,

start, end, Shader.TileMode.CLAMP)

// ReDraw

invalidate()

}

override fun onDraw(canvas: Canvas) {

super.onDraw(canvas)

canvas.drawRect(rect, paint)

}

}

I also create an open source project GradientView with this custom view:

https://github.com/lopspower/GradientView

implementation 'com.mikhaellopez:gradientview:1.1.0'

來源:https://stackoverflow.com/questions/5976805/android-linearlayout-gradient-background

總結(jié)

以上是生活随笔為你收集整理的android layout background,Android LinearLayout Gradient Background的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 思思精品视频 | 日韩网红少妇无码视频香港 | 黄色激情视频在线观看 | 国产剧情一区在线 | sese在线| 成年人在线免费观看视频网站 | av网站免费在线播放 | 嫩草午夜少妇在线影视 | 亚洲制服丝袜在线播放 | 久久性色| 九九午夜 | 强行挺进白丝老师翘臀网站 | 国产精品麻豆成人av电影艾秋 | 日本少妇videos高潮 | 夜色快播| 国产高清视频在线观看 | 国产毛片久久久 | 免费又黄又爽又猛大片午夜 | 性做爰裸体按摩视频 | 欧美激情校园春色 | 黄色av电影在线观看 | 亚洲福利午夜 | 久热久 | 男男一级淫片免费播放 | 久久久久无码国产精品一区李宗瑞 | 福利第一页 | 国产一区二区三区四区hd | 色av影院| 精品1区2区3区 | 成人看片网 | 18黄暴禁片在线观看 | 少妇人妻偷人精品无码视频新浪 | 最黄一级片| 少妇高潮大叫好爽喷水 | 日韩精品久久久久久 | 毛片a级片| 亚洲欧美综合久久 | 国产精品久久久久久久久久久久久久久久久 | 手机看片1024日韩 | 不卡日本| 中文字幕dvd | 国产网站大全 | 色播视频在线观看 | 国产成人免费网站 | 黑人性xxx| 四虎av影视 | 免费成人激情视频 | 91极品身材尤物theporn | 青青草五月天 | 岛国av不卡| 日韩视频一区二区三区在线播放免费观看 | 国产一级特黄视频 | 亚洲成熟丰满熟妇高潮xxxxx | 毛片毛片毛片毛片毛片 | 欧美久久久久久又粗又大 | 偷拍青青草 | 天天添| 超碰美女在线 | 国产伦精品一区二区三区免费视频 | 久久精品国产免费 | 婷婷久久久久久 | 欧美人与禽zoz0性3d | 免费观看的av | 亚洲风情亚aⅴ在线发布 | 动漫同人高h啪啪爽文 | 一本久久精品一区二区 | 超碰人人做 | 黑人巨大精品人妻一区二区 | 驯服少爷漫画免费观看下拉式漫画 | 精品国产欧美日韩 | 激情综合站| 国产在线看一区 | 五月天激情综合 | 尤物在线免费视频 | 亚洲色图欧美自拍 | 国产网站免费在线观看 | 办公室荡乳欲伦交换bd电影 | 好看的黄色录像 | a天堂资源| 热热热热色 | 中日韩精品在线 | 91精品国产自产精品男人的天堂 | 亚洲h片 | 欧美久久久久久又粗又大 | 黄色片网站在线免费观看 | 成人综合精品 | 久久青娱乐 | 国产无套精品一区二区三区 | 午夜精品久久久久久久久 | 18岁毛片| 欧美日韩三区 | 国产精品调教视频 | 1区2区视频| 精品人妻一区二区三区蜜桃视频 | 91av日本| 国产一级免费观看 | 亚洲欧美日韩在线看 | 人人爽在线 | 91精品免费在线 |