如何讓安卓(Android)子控件超出父控件的範圍顯示

下面我們來看一下關於安卓(Android)子控件超出父控件的範圍顯示出來的方法,希望這篇文章能夠幫助到各位安卓(Android)的開發者們,有碰到此問題的朋友可以進來看看哦。

廢話不多說,直接上代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:clipChildren="false">
  
 <ImageView
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_marginBottom="60dp"
  android:background="@mipmap/www" />
  
  
 <LinearLayout
  android:id="@+id/ll_bottom"
  android:layout_width="match_parent"
  android:layout_height="60dp"
  android:layout_alignParentBottom="true"
  android:background="#F8549D"
  android:elevation="10dp"
  android:orientation="horizontal">
  
  <RelativeLayout
   android:layout_width="0dp"
   android:layout_height="match_parent"
   android:layout_gravity="bottom"
   android:layout_weight="1">
  
   <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:src="@mipmap/ic_launcher" />
  
  </RelativeLayout>
  
  <RelativeLayout
   android:layout_width="0dp"
   android:layout_height="match_parent"
   android:layout_gravity="bottom"
   android:layout_weight="1">
  
   <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:src="@mipmap/ic_launcher" />
  
  </RelativeLayout>
  
  <RelativeLayout
   android:layout_width="70dp"
   android:layout_height="70dp"
   android:layout_gravity="bottom"
   android:background="@drawable/bottom_bg_shape">
  
   <ImageView
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_centerInParent="true"
    android:src="@mipmap/icon_go" />
  
  </RelativeLayout>
  
  
  <RelativeLayout
   android:layout_width="0dp"
   android:layout_height="match_parent"
   android:layout_gravity="bottom"
   android:layout_weight="1">
  
   <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:src="@mipmap/ic_launcher" />
  
  </RelativeLayout>
  
  <RelativeLayout
   android:layout_width="0dp"
   android:layout_height="match_parent"
   android:layout_gravity="bottom"
   android:layout_weight="1">
  
   <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:src="@mipmap/ic_launcher" />
  
  </RelativeLayout>
 </LinearLayout>
  
</RelativeLayout>
 

這張圖呢是我剛剛做的,效果是參考了酷狗音樂播放器來完成的,我想說明重點在底部的導航欄:如圖


再來一張反效果預覽圖:


如何使得藍色圓形的播放鍵的顯示越過粉色的範圍。當然經過合理的佈局是可以達到這樣的效果的,但是卻有更簡單的方法。也就是在根佈局的屬性中加入一個來自Android自身提供的屬性:

?
1
android:clipChildren="false"

屬性解釋和說明:

    1、android:clipChildren的意思:是否限制子View在其範圍內

     2、可以通過android:layout_gravity控制超出的部分如何顯示。

    3、只需在根節點設置android:clipChildren爲false即可,默認爲true

總結

以上就是如何讓安卓(Android)子控件超出父控件的範圍顯示出來的全部內容,大家學會了嗎?希望本文可以幫助到各位。






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章