Reputation: 177
I'd like to a create an ImageView
which is fill the whole screen. And I'd like to make this ImageView
to have a color (green,black,transparent etc.).
I faced with a problem which is wierd to me because the problem is, when I set the ImageView
background for an image using @drawable
resources then it's looking good, but when I using @color
resources then the ImageView
is invisble. How is it possible?
Check xml file below:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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"
android:fillViewport="true"
android:id="@+id/scrollView">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:id="@+id/relativeinfo1">
<View
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_above="@+id/titleinfo"
android:layout_toRightOf="@+id/imageinfo"/>
<TextView
android:id="@+id/titleinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_toRightOf="@+id/imageinfo"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:id="@+id/mooobil"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:id="@+id/telefoneeo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="email"
android:id="@+id/emailese"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:id="@+id/honlapese"/>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/imageinfo"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"/>
<View
android:layout_width="wrap_content"
android:layout_height="15dp"
android:id="@+id/view1"
android:layout_below="@+id/imageinfo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cimtext"
android:textStyle="bold"
android:text="Cím: "
android:textSize="15dp"
android:textColor="#000000"
android:visibility="invisible"/>
<View
android:layout_width="wrap_content"
android:layout_height="10dp"
android:id="@+id/vonal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#FFD700" />
<View
android:layout_width="wrap_content"
android:layout_height="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="@+id/vonal2"
android:background="#FFD700"/>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="300dp"
tools:context=".MainActivity"
android:id="@+id/relativemaplayout"
android:clickable="true">
<fragment
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
<ImageView
android:id="@+id/transparent_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ek_logo"/>
</RelativeLayout>
This way I can see ek_logo picture on the screen but when I change that line android:background="@drawable/ek_logo"
into this android:background="@color/colorPrimary"/>
there is nothing I can see.
I hope you could help me.
Upvotes: 0
Views: 1359
Reputation: 1801
@J Doe.
change your layout_height
for ImageView
also since your using Relative Layout
specify below which view you have to display ImageView
. Also if you want to align ImageView on the top of map fragment then use android:layout_alignTop
<ImageView
android:id="@+id/transparent_image"
android:layout_alignTop="@+id/relativemaplayout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/app_name"
android:background="@color/colorPrimaryDark" />
Upvotes: 1
Reputation: 1762
try to set
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@color/colorPrimary"/>
Upvotes: 0
Reputation: 1328
You should only set an ImageView's content with:
android:src="@drawable/my_drawable"
If you just want a background color behind your image, simply change the root view's background color:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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"
android:fillViewport="true"
android:background="@android:color/darker_gray"
android:id="@+id/scrollView">
Then, whenever you only want to see the color , just set the visibility of the ImageView to GONE or INVISIBLE
imageView.setVisibility(View.GONE); // or View.INVISIBLE
or:
imageView.setImageResource(0);
Upvotes: 0