2016-03-30 30 views
1

XMLファイルに設定した背景画像の不透明度を変更する方法はありますか?しかし、私はこの同じ問題について研究したので、xmlファイルに入れるテキストを正当化したいと思っていました。 Androidスタジオはテキストをまだ正当化していません。しかし、私はtextviewの代わりにwebviewに変更しようとしましたが、私はレイアウトを呼び出すためにcaseステートメントを使用し、webviewのjavaファイルはフラグメントではなくむしろアクティビティであるため、多くのエラーをメインアクティビティjavaに呼び出すことがあります。あなたの反応は非常に高く評価されるでしょう。ここで背景画像の不透明度を変更するにはどうすればよいですか?

は、XMLファイル

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="center" 
android:orientation="vertical" 
android:background="@drawable/minnions1" 
android:id="@+id/minnions1" 
> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Safe and Responsible usage of Computer,Internet and Email" 
    android:textColor="@android:color/black" 
    android:textSize="20sp" 
    android:id="@+id/title1" 
    android:layout_marginTop="125dp" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:gravity="center" 
    /> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:gravity ="center" 
    android:fillViewport="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="100dp" 
    android:id="@+id/scrollView" 
    > 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:textColor="#000" 
     android:textColorLink="@android:color/black" 
     android:textSize="18sp" 
     android:text="Using facilities and equipments should always be safe and useful in Information and Communication Technology (ICT) 
like computer, email, and internet. It is important for us to study the guides and safe usage of computer, internet 
and email in schools.\n \n" 
     android:drawablePadding="5dp" 
     android:layout_marginLeft="40dp" 
     android:layout_marginRight="20dp" 
     android:layout_below="@+id/content1" 
     android:layout_centerHorizontal="true" 
     /> 
</ScrollView> 
</LinearLayout> 

また、ここではjavaファイルがある

package com.android.pet.view; 

import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 

import com.doepiccoding.navigationdrawer.R; 

public class Lesson1 extends Fragment{ 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.onepointone, null); 
     return rootView; 
    } 
} 
+0

あなたのwebviewはどこにあるのですか?あなたのwebviewはどこにあるのですか? – sharan

答えて

3

この

View backgroundimage = findViewById(R.id.background); 
Drawable background = backgroundimage.getBackground(); 
background.setAlpha(80); 

ここで背景画像をお試しくださいですありがとうございことはご理解のあるあなたは置き換えることができます背景を不透明に設定するレイアウト

+0

public View onCreateView(LayoutInflaterインフレータ、ViewGroupコンテナ、Bundle savedInstanceState){ View rootView =インフレータ.inflate(R.layout.onepointone、null); View backgroundimage = findViewById(R.id.minnions1); 描画可能な背景= backgroundimage.getBackground(); background.setAlpha(80); return rootView; }} しかし方法findViewByIdを解決できませんと言ってfindViewById下の赤い線がある(INT) – Dreamer

+0

@Dreamer rootView.findViewById(R.id.minnions1)を使用してみてください。 – sharan

+0

ありがとう、それは今、完璧に正常に動作します – Dreamer

2

あなたはプログラムでsetAlpha(50)メソッドを使用して変更することができ、xmlではandroidを使うことができます:alpha = "0.5" 1は最大で0.5は半透明です。

また、デザインを少し変更することもできます。 の代わりにこれをやって、この

<FrameLayout> 
<ImageView 
    android:background="@drawable/background" 
    android:alpha="0.3" /> 
<LinearLayout> 
//Same as before 
</LinearLayout> 

はあなたの親でframeLayout作り、子供、残りは同じままになりますようご線形レイアウトを置けばいい。あなたのイメージビューのマッチする親の高さの幅を与えてください。

+0

しかし、それは私のXMLファイル内に実装する場合は、私のtextviewに影響を与えます。私はすでにそれを試して、全体のレイアウトが影響を受けた。私がしたいのは、テキストビューではなく影響を受ける背景画像だけです – Dreamer

+0

その場合は、少しデザインを変更し、framelayoutを使用して、その内部にimageviewを使用して、その画像のアルファを変更する必要があります。他に影響を与える –

+0

私は自分の答えを更新しました –

関連する問題