C Sharper
C Sharper

Reputation: 8626

Background image comming in wrong way

I have just done code to take image at background of login form.

Code is as follows:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
    android:layout_height="510dip"
    android:layout_marginTop="10dip"
    android:background="#DDDDDD" >

        <LinearLayout
           android:id="@+id/tv_un"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10pt"
        android:textColor="#444444"            
            android:orientation="vertical" >


             <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" 
        android:src="@drawable/capture"/>


            <TextView
                android:id="@+id/view_username"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/view_username" />

            <EditText
              style="@style/CodeFont"
               android:background="@android:drawable/editbox_background"
                android:ems="10"                
                android:inputType="textPersonName" >

                <requestFocus />
            </EditText>

            <TextView
                android:id="@+id/view_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:text="@string/view_password" />

            <EditText
                android:background="@android:drawable/editbox_background"
                android:id="@+id/txt_password"
                  style="@style/CodeFont"
                android:ems="10"
                android:text="@string/view_password"
                android:inputType="textPassword" />

            <Button
                android:id="@+id/btn_login"
               android:layout_width="100dip"
        android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:text="@string/btn_login" />

            <TextView
                android:id="@+id/link_to_register"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:gravity="center"
                android:text="@string/link_to_register" />

        </LinearLayout>
    </ScrollView>

App looks like:

enter image description here

As we can see image has came above controls.

I wanted to have image on full screen and controls over the image.

How can i have it?

What changes i have to make in my current code.

Please help me.

Edit:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
    android:layout_height="510dip"
    android:layout_marginTop="10dip"
    android:background="#DDDDDD" >

        <LinearLayout
           android:id="@+id/tv_un"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10pt"
        android:textColor="#444444"            
            android:orientation="vertical" 
        android:src="@drawable/capture"    >

Upvotes: 1

Views: 324

Answers (4)

Kirti
Kirti

Reputation: 701

   <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
      android:background="@drawable/capture"
   android:layout_marginTop="10dip"
   >
 </ScrollView>

try to use this fill parent insted of defining height

and add image in scrollview or linearlayout

      OR(use one of this)
 for linearlayout


     <LinearLayout
       android:id="@+id/tv_un"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:background="@drawable/capture"
      android:textSize="10pt"
      android:textColor="#444444"            
       android:orientation="vertical" >

there is no need of image view tag for background image

Upvotes: 2

Piyush
Piyush

Reputation: 18933

Give

android:src="@drawable/capture"

to LinearLayout...

And yes try to set width and height of LinearLayout to match_parent

Use this:

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:id="@+id/scrollView1"
   android:layout_width="fill_parent"
   android:layout_height="match_parent"
   android:layout_marginTop="10dip"
   android:background="@drawable/ic_launcher"
   android:background="#DDDDDD" >

   <ScrollView
    android:id="@+id/scrollView2"
    android:layout_width="fill_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/tv_un"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:textColor="#444444"
        android:textSize="10pt" >

        <TextView
            android:id="@+id/view_username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/view_username" />

        <EditText
            style="@style/CodeFont"
            android:background="@android:drawable/editbox_background"
            android:ems="10"
            android:inputType="textPersonName" >

            <requestFocus />
        </EditText>

        <TextView
            android:id="@+id/view_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="@string/view_password" />

        <EditText
            android:id="@+id/txt_password"
            android:background="@android:drawable/editbox_background"
            android:ems="10"
            android:inputType="textPassword"
            android:text="@string/view_password" />

        <Button
            android:id="@+id/btn_login"
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="@string/btn_login" />

        <TextView
            android:id="@+id/link_to_register"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:gravity="center"
            android:text="@string/link_to_register" />
    </LinearLayout>
    </ScrollView>

   </LinearLayout>

Upvotes: 2

mouso mashakel
mouso mashakel

Reputation: 41

you can make it by using this code in the activity class

View LinearLayout = (View) findViewById(R.id.tv_un);     
LinearLayout.setBackgroundResource(R.drawable.capture);

and delete this from the layout

 <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" 
    android:src="@drawable/capture"/>

Upvotes: 0

MysticMagicϡ
MysticMagicϡ

Reputation: 28823

Try giving

android:background="@drawable/capture"

to your main outer layout. What you have done is set the image to imageview. Not a background

Upvotes: 1

Related Questions