2012-11-25 19 views
-5

我正在製作一個應用程序,我必須在一個XML文件中使用兩個圖像。 (一個是徽標,另一個是一些登錄模式)。在模式圖像上,我必須設置兩個EditText。我怎樣才能做到這一點???如何通過ImageView使用EditText

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" > 
<ImageView 
. 
. 
. 
. 
./> 

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:background="@drawable/some image" 
      android:layout_marginLeft="200dp" 
      android:layout_marginBottom="300dp" 
      android:layout_marginTop="80dp"> 

      <LinearLayout 
      android:layout_height="fill_parent" 
      android:layout_width="fill_parent" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:orientation="vertical"> 
      <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
          /> 
     </LinearLayout> 
    </RelativeLayout> 
    </relativeLayout> 
+0

你想有幾個EditTexts背景之上? – PearsonArtPhoto

+0

是... 2編輯文本的登錄ID和Passwrd – anshika

回答

2

如果我正確地理解這個,你基本上想要在前臺有兩個EditTexts的背景。

做到這一點的最好方法是通過相對佈局。像這樣的東西會工作(注意,這是僞代碼,所以它不會直接工作)

<RelativeLayout> 

    <ImageView 
     android:height="fill_parent" 
     android:src="@drawable/some_image" 
     android:width="fill_parent" /> 

    <EditText 
     android:id="@+id/edit_text1" 
     android:layout_alignParentBottom="true" /> 

    <EditText 
     android:id="@+id/edit_text2 " 
     android:layout_above="@id/edit_text1" /> 

</RelativeLayout> 
+0

其實,那裏在XML中不是唯一的一個圖像..在同一個XML中有兩個圖像,一個在右上角,另一個在左下角,所以我想在右上圖像中設置編輯文本.. – anshika

+0

更簡單,你可以將EditText對齊在右上方的圖像 – PearsonArtPhoto

+1

thnx brother ..我已經得到了結果.. :) – anshika

1

你的問題有點含糊,但你可以很容易地使用Relativelayout,將您的ImageView上述EditTexts。

一個基本的例子是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/image" /> 

</RelativeLayout> 
+0

PLZ看到我的代碼,並告訴我,如果我這樣做的權利? – anshika

+0

對不起,我不能回答我的問題becoz沒有太多的聲譽..'( – anshika

+1

點擊「編輯」在你的問題的左下角添加代碼。 – Sam

0

要放置imageview的上面的EditText:

EditText edit = (EditText)findViewById(R.id.YOUR_EDITTEXT_ID); 
ImageView image = (ImageView)findViewById(R.id.YOUR_IMAGEVIEW_ID); 
image.setImageBitmap(YOUR_BITMAP); 
edit.bringToFront(); 

上面的代碼將帶來沿着z軸的ImageView上述的EditText。當然,你必須以XML或編程方式來定位它們。

0

謝謝大家的幫助。我已經完成了我的任務。這個應用程序是用於平板電腦的,因此可以根據這一點來調整頁邊距。這裏是代碼..

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

<ImageView 
    android:id="@+id/login" 
    android:layout_width="648dp" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="640dp" 
    android:layout_marginTop="40dp" 
    android:src="@drawable/ic_login" /> 

<EditText 
    android:id="@+id/et1" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:cursorVisible="true" 
    android:background="#000" 
    android:singleLine="true" 
    android:layout_marginTop="100dp" 
    android:layout_marginLeft="710dp" 
    android:layout_marginRight="193dp" 
    android:textColor="#fff"/> 

<EditText 
    android:id="@+id/et1" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:cursorVisible="true" 
    android:background="#000000" 
    android:singleLine="true" 
    android:layout_marginTop="127dp" 
    android:layout_marginLeft="710dp" 
    android:layout_marginRight="193dp" 
    android:textColor="#fff"/> 

<ImageView 
    android:id="@+id/logo" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="420dp" 
    android:layout_marginLeft="2dp" 
    android:src="@drawable/ic_glogo" /> 


</RelativeLayout>