2017-09-22 24 views
-6

我想添加分隔線(水平或垂直兩個視圖之間的平滑透明線)我怎麼能實現這裏是我的示例code.i需要添加水平線用戶名和密碼(水平)之間的並且還包括用戶圖標和用戶名提示(垂直地)我想添加分隔線在Android應用程序中的兩個視圖

<LinearLayout 
      android:gravity="top" 
      android:divider="?android:dividerHorizontal" 
      android:layout_width="300dp" 
      android:layout_marginLeft="20dp" 
      android:layout_height="wrap_content" 
      android:id="@+id/liner" 
      android:orientation="vertical"> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/user" 
       android:id="@+id/username" 
       android:textColor="#bbc" 
       /> 
      <EditText 
       android:layout_width="300dp" 
       android:layout_height="wrap_content" 
       android:hint="@string/usr_name" 
       android:textColorHint="#bbc" 
       android:backgroundTint="@android:color/transparent" 
       android:textColor="@android:color/white"/> 
     </LinearLayout> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/paswd" 
       android:id="@+id/password" 
       android:textColor="#bbc" 
       /> 
      <EditText 
       android:layout_width="300dp" 
       android:layout_height="wrap_content" 
       android:hint="@string/passwd" 
       android:textColorHint="#bbc" 
       android:backgroundTint="@android:color/transparent" 
       android:textColor="@android:color/white"/> 
     </LinearLayout> 
    </LinearLayout> 
+0

之前問出這樣的問題 – akhilesh0707

+0

請[參考這個問題(https://stackoverflow.com/questions/5049852/android-drawing-separator-divider-line-in-請做谷歌佈局) –

+3

[Android Layout Drawing Separator/Divider Line in Layout?](https://stackoverflow.com/questions/5049852/android-drawing-separator-divider-line-in-layout) – akhilesh0707

回答

0

只需創建爲用戶名和PAS兩個線性佈局之間的userName

<View 
android:layout_width="match_parent" 
android:layout_height="2dp" 
android:color="@color/divider_color" 
android:id="@+id/divider" /> 
之間& passowrd

1

另一個視圖之間劍使用以下命令:

<View 
     android:id="@+id/line" 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="@color/black"/> 
2

使下面的代碼可繪製文件,分隔線,和你需要的地方使用它,根據您的選擇也改變顏色。

<View xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="0.7dp" 
    android:background="#ebebeb" /> 
0

您可以通過使用View標籤,其高度(或寬度,如果它是垂直的)之間的意見1DP的加分頻器要劃分:

<View 
android:id="@+id/line" 
android:layout_width="match_parent" 
android:layout_height="1dp" 
android:background="@color/yourColor/> 
3

的水平線

<LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="username" 
      android:id="@+id/username" 
      android:textColor="#bbc" 
      /> 
     <View 
      android:layout_width="0.5dp" 
      android:layout_height="match_parent" 
      android:background="#ebebeb" 
      android:layout_margin="@dimen/margin_5"/> 
     <EditText 
      android:layout_width="300dp" 
      android:layout_height="wrap_content" 
      android:hint="usr_name" 
      android:textColorHint="#bbc" 
      android:backgroundTint="@android:color/transparent" 
      android:textColor="@android:color/white"/> 
    </LinearLayout> 

對於垂直線

<View 
     android:layout_width="match_parent" 
     android:layout_height="0.5dp" 
     android:background="#cd2121" 
     android:layout_margin="@dimen/margin_5"/> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="@dimen/text_10"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="password" 
      android:id="@+id/password" 
      android:textColor="#bbc" 
      /> 
     <View 
      android:layout_width="0.5dp" 
      android:layout_height="match_parent" 
      android:background="your color" 
      android:layout_margin="@dimen/margin_5"/> 
     <EditText 
      android:layout_width="300dp" 
      android:layout_height="wrap_content" 
      android:hint="password" 
      android:textColorHint="#bbc" 
      android:backgroundTint="@android:color/transparent" 
      android:textColor="@android:color/white"/> 
    </LinearLayout> 
1

嘗試下面的代碼

<View xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="0.5dp" 
android:background="#cd2121" /> 
相關問題