android實現陰影
1. 最近在做Android應用,想做出類似的圖片陰影效果,怎麼實現
其實這種陰影很簡單,就是做一個漸變的黑色陰影然後覆蓋在原圖就OK了,至於怎麼做的話LZ可以看下PHOTOSHOP之類的漸變陰影功能,幾分鍾就可以做好了
2. Android 5.0 elevation 設置陰影無效
elevation 設置陰影需要注意兩點:
1、view需要設置背景
2、陰影是繪制在父控制項上的,子控制項和父控制項之間要留空隙,用padding也不行
在開發過程中有過這樣的布局:
我子Linearlayout是設置的圓角背景,結果這樣的效果是:只有圓角的便便才有一丁點的陰影,原因是父布局設置的是padding,子控制項是match_parent,空隙不足導致,將子布局改為margin,去掉父控制項的padding就行了
3. android 怎麼給button添加陰影
在button中添加elevation屬性。注意一點:他的父控制項要設置的大一點,不然顯示不出來
4. android 圓角邊框 陰影邊框怎麼設置
所謂添加陰影,就是兩個畫布從重疊,上方的畫布小於下方的畫布,陰影顏色為下方的畫布的顏色。
item 中shape 的屬性 (rectangle:矩形;line:線性;oval:橢圓;ring:環形),默認為矩形
corners //設置圓角幅度,必須是在shape=rectangle的時候,corners才有效
<corners
Android:radius="dimension" //全部的圓角半徑
android:topLeftRadius="dimension" //左上角的圓角半徑
android:topRightRadius="dimension" //右上角的圓角半徑
android:bottomLeftRadius="dimension" //左下角的圓角半徑
android:bottomRightRadius="dimension" /> //右下角的圓角半徑
eg:<corners android:radius="10dp" />
solid用以指定內部填充色
e.g:<solid android:color="color" />
gradient //定義漸變色,可以定義兩色漸變和三色漸變,及漸變樣式
linear(線性漸變)、radial(放射性漸變)、sweep(掃描式漸變), 在構造放射性漸變時,要加上android:gradientRadius屬性(漸變半徑),即必須指定漸變半徑的大小才會起作用。
<gradient
android:type=["linear" | "radial" | "sweep"] //共有3中漸變類型
android:angle="integer" //漸變角度,必須為45的倍數,0為從左到右,90為從上到下
android:centerX="float" //漸變中心X的相當位置,范圍為0~1
android:centerY="float" //漸變中心Y的相當位置,范圍為0~1
android:startColor="color" //漸變開始點的顏色
android:centerColor="color" //漸變中間點的顏色,在開始與結束點之間
android:endColor="color" //漸變結束點的顏色
android:gradientRadius="float" //漸變的半徑,只有當漸變類型為radial時才有效
android:useLevel=["true" | "false"] /> //使用LevelListDrawable時就要設置為true。設為false時才有漸變效果
stroke //這是描邊屬性,可以定義描邊的寬度,顏色,虛實線等
<stroke
android:width="dimension" //描邊的寬度
android:color="color" //描邊的顏色 // 以下兩個屬性設置虛線
android:dashWidth="dimension" //虛線的寬度,值為0時是實線
android:dashGap="dimension" /> //虛線的間隔
5. Android studio中控制項TextView學習
TextView作為Android開發中的基礎控制項,其學習內容豐富且實用。下面將對TextView的學習進行概括性介紹,包含其基本屬性、陰影效果以及實現跑馬燈的三種方法。
**基礎屬性代碼練習**:在Android開發中,TextView用於顯示文本信息。學習之初,可以通過設置TextView的文本、字體大小、顏色等基礎屬性進行實踐操作,這些屬性通過set方法進行調整。
**帶陰影的TextView代碼練習**:為TextView添加陰影效果,可以提升UI的美觀度。實現該功能可通過修改TextView的陰影屬性,例如設置陰影顏色、陰影半徑、陰影偏移等。具體代碼示例為:`myTextView.setShadowLayer(3f, 1f, 1f, Color.GRAY);`。
**實現跑馬燈的三種方式**:跑馬燈效果在Android應用中常見,用於顯示滾動的文字或圖片。實現方式有三種:
1. **手動點擊TextView**:用戶點擊TextView時觸發滾動效果。實現時需監聽TextView的點擊事件,並在事件處理中實現滾動邏輯。
2. **自定義MyTextView**:創建一個自定義的TextView類,重寫其滾動邏輯,無需用戶點擊即可自動啟動滾動。
3. **改回TextView並加requestFocus**:通過設置TextView的requestFocus屬性,使其在界面中獲得焦點後自動啟動滾動效果。
上述代碼示例旨在展示實現思路,具體實現細節需根據項目需求和API版本進行相應調整。
**推薦學習資源**:對於初學者而言,系統學習Android開發技術是提升的關鍵。推薦《Android核心技術進階手冊》一書,內容全面且適合初學者,幫助鞏固基礎並深入理解Android開發。如果你正在學習階段或已有1-2年開發經驗,這本資料將對你有很大幫助。
**總結**:在Android開發中,掌握基礎控制項如TextView的運用是必不可少的技能。隨著學習的深入,更多控制項和功能將逐漸掌握。Android開發之路充滿挑戰,但通過不斷實踐和學習,每一步積累都將為未來的技術成長鋪平道路。希望每位開發者都能在Android領域探索出一片屬於自己的天地。
6. 安卓怎麼在linearLayout或者其他一些組件底部添加陰影
有兩種解決方案:
1、使用9-patch 圖片,製作一個陰影部分的圖片,然後橫向拉伸即可
2、使用layer-list
在res/drawable下,新建background_with_shadow.xml文件,該文件代碼如下:
<?xmlversion="1.0"encoding="utf-8"?>
<layer-listxmlns:android="http://schemas.android.com/apk/res/android">
<!--bottomshadow-->
<item>
<shapeandroid:shape="rectangle">
<!--fromtoptobottom-->
<gradient
android:angle="90"
android:centerColor="#bbbbbb"
android:endColor="#d5d5d5"
android:startColor="#a9a09d"/>
<cornersandroid:radius="5dp"/>
</shape>
</item>
<!--content-->
<itemandroid:bottom="2dp">
<shapeandroid:shape="rectangle">
<solidandroid:color="#50c1e9"/>
<cornersandroid:radius="5dp"/>
</shape>
</item>
</layer-list>
使用background_with_shadow.xml文件
假設有bottom_shadow.xml文件,內容如下:
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#bfbfbf">
<LinearLayout
android:layout_marginTop="40dp"
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="vertical"
android:background="@drawable/background_with_shadow">
</LinearLayout>
<TextView
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="活動海報"/>
</LinearLayout>
效果圖如下