2016-09-19 2 views
0

Я новичок в развитии Android. Моя цель - установить фоновое изображение с прозрачным цветом градиента, я пробовал много способов, но я не могу достичь этой цели. Может кто-нибудь мне помочь? Я прикрепил образец экрана.Как установить фоновое изображение с прозрачным цветом градиента в Android?

enter image description here

Исходный код

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/bc" 
    android:orientation="vertical" 
    android:paddingLeft="20dp" 
    android:alpha="0.7" 
    android:id="@+id/about" 
    android:paddingRight="20dp" 
    android:paddingTop="60dp"> 

    <android.support.design.widget.TextInputLayout 
     android:id="@+id/otp_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:hintTextAppearance="@style/hintStyle"> 

     <EditText 
      android:id="@+id/mobNo" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/hint_mob" 
      android:inputType="number" 
      android:singleLine="true" 
      /> 
    </android.support.design.widget.TextInputLayout> 


    <Button 
     android:id="@+id/submit" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="40dp" 
     android:background="@color/colorPrimary" 
     android:text="@string/submit" 
     android:textColor="@android:color/white"/> 

</LinearLayout> 

Заранее спасибо.

+0

делитесь тем, что вы сделали. Также проверьте этот http: // stackoverflow.com/questions/3823607/how-to-make-transparent-gradient – masp

+0

добавить свой xml-файл – DKV

+0

@VV, я обновил свой вопрос – Kalanidhi

ответ

2

Ниже приведены шестнадцатеричные значения -

100% — FF 
95% — F2 
90% — E6 
85% — D9 
80% — CC 
75% — BF 
70% — B3 
65% — A6 
60% — 99 
55% — 8C 
50% — 80 
45% — 73 
40% — 66 
35% — 59 
30% — 4D 
25% — 40 
20% — 33 
15% — 26 
10% — 1A 
5% — 0D 
0% — 00 

, если вы хотите установить 50% прозрачный черный цвет Д.О., как показано ниже -

<color name="transparentBlack">#80000000</color> 

Update:

Вы можете использовать градиент, как показано ниже, для установки фона -

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <gradient 
     android:startColor="#008000" 
     android:endColor="#FFFF00" 
     android:angle="90" 
     android:type="linear" 
     android:dither="true" 
     /> 
</shape> 

Существует название цвета «GreenYellow», если это то, что у ищет цветовой код, как цен ниже

GreenYellow: ADFF2F 
+1

как сформировать два цвета с градиентным форматом? Как зеленый и желтый с градиентным форматом – Kalanidhi

+0

@ Kalanidhi: проверьте мое обновление :) – kevz

2

просто приложить

100% — FF 
95% — F2 
90% — E6 
85% — D9 
80% — CC 
75% — BF 
70% — B3 
65% — A6 
60% — 99 
55% — 8C 
50% — 80 
45% — 73 
40% — 66 
35% — 59 
30% — 4D 
25% — 40 
20% — 33 
15% — 26 
10% — 1A 
5% — 0D 
0% — 00 

этих два символа перед ваш зеленый цвет. например # 62cf51 - ваш стартовый зеленый цвет, вы можете использовать # 9962cf51 цвет для прозрачности. В этом примере я добавил 60% прозрачности, вы можете использовать согласно вашему требованию.

1

Вы всегда можете добиться этого, создав новый ресурс xml. создать новую Drawable ресурсу

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <gradient 
     android:startColor="@android:color/transparent" 
     android:endColor="#20403f4c" 
     android:angle="90" 
     android:type="linear" 
     android:dither="true" 
     /> 
</shape> 

Установите его на фоне какого-либо элемента. Если вы хотите изменить прозрачность, ответ выше поможет.

1
Try this. 

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/images" 
     android:text="Hello World!" /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:background="@drawable/trans" 
     android:paddingBottom="50dp" 
     android:paddingTop="50dp"> 

     <EditText 

      android:id="@+id/ed_text1" 
      android:layout_width="match_parent" 
      android:layout_height="45dp" 
      android:layout_margin="15dp" 
      android:background="#80ffffff" /> 

     <EditText 
      android:id="@+id/ed_text2" 
      android:layout_width="match_parent" 
      android:layout_height="45dp" 
      android:layout_below="@+id/ed_text1" 
      android:layout_margin="15dp" 
      android:background="#80ffffff" /> 


    </RelativeLayout> 


</RelativeLayout> 



and trans.xml drawable 


<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <gradient 
     android:startColor="#6066ff66" 
     android:centerColor="#6066ff66" 
     android:endColor="#6066ff66" 
     android:angle="90" 
     /> 
</shape> 
1

Вы можете отредактировать это, как хотите. добавить редактировать текст и все ниже макете

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/about" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 

android:orientation="vertical"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="50" 
    android:background="@mipmap/ic_launcher" 
    android:orientation="vertical" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="50" 
    android:background="@mipmap/ic_launcher" 
    android:orientation="vertical"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#BF228B22"> 

    </RelativeLayout> 


</LinearLayout> 

+0

@ Kalanidhi: у вас получился ответ? – DKV

+0

Да, но мне нужно еще одно разъяснение. Как сделать цвет градиента зеленым с желтым? – Kalanidhi

+0

Вам нужна помощь? – DKV

1

попробовать это анс:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#ffff99" 
android:orientation="vertical" 
android:id="@+id/about" 
> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:background="#20403f4c" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true"> 

<android.support.design.widget.TextInputLayout 
    android:id="@+id/otp_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:hintTextAppearance="@style/hintStyle"> 

    <EditText 
     android:id="@+id/mobNo" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/hint_mob" 
     android:inputType="number" 
     android:singleLine="true" 
     /> 
</android.support.design.widget.TextInputLayout> 


<Button 
    android:id="@+id/submit" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="80dp" 
    android:background="@android:color/transparent" 
    android:text="submit" 
    android:textColor="@android:color/black"/> 
</RelativeLayout> 

или изменить фон этого андроида: фон = "# 20403f4c" в соответствии с ваша прозрачность