2016-11-02 4 views
0

이 문제가 있습니다. 나는이 레이아웃이 이미지를 넣을 : 이미지의이 이미지의 크기를 올바르게 조정하고 editText를 이미지에 삽입하는 방법은 무엇입니까?

enter image description here

크기가 297x199입니다. 안드로이드에 나는 같이,이 이미지에 검은 글고 치기를 넣을 : enter image description here

을하지만 난 내 프로젝트에 넣어하려고 할 때이 얻을 : enter image description here

을 그리고로의 EditText를 추가하는 것은 불가능합니다 여기, 정확한 크기로.

내 프로젝트의 XML은 이렇게 할 수있는 방법이

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:background="EBEBF1" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.CardView 
     android:id="@+id/card_view" 
     android:layout_width="match_parent" 
     android:layout_height="230dp" 
     android:layout_marginTop="9dp" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginLeft="9dp" 
     android:layout_marginRight="9dp"> 

     <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


      <TextView 
       android:text="@string/cas" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="39dp" 
       android:layout_marginStart="39dp" 
       android:id="@+id/textView2" 
       android:textStyle="normal|bold" 
       android:textSize="18sp" 
       android:textColor="#000" 
       android:layout_marginBottom="16dp" 
       android:layout_alignBottom="@+id/imageView11" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" /> 

      <ImageView 
       android:layout_width="250dp" 
       app:srcCompat="@drawable/photoframe" 
       android:id="@+id/imageView11" 
       android:layout_marginTop="49dp" 
       android:layout_height="90dp" 
       android:layout_alignParentTop="true" 
       android:layout_alignLeft="@+id/textView2" 
       android:layout_alignStart="@+id/textView2" 
       android:layout_marginLeft="22dp" 
       android:layout_marginStart="22dp" /> 

      <EditText 
       android:layout_height="35dp" 
       android:inputType="numberSigned" 
       android:ems="10" 
       android:background="#000" 
       android:id="@+id/editText2" 
       android:layout_width="65dp" 
       android:layout_marginLeft="46dp" 

       android:layout_alignBottom="@+id/textView2" 
       android:layout_toRightOf="@+id/textView2" 
       android:layout_marginStart="46dp" /> 

     </RelativeLayout> 

    </android.support.v7.widget.CardView> 

</RelativeLayout> 

있습니까? 이 이미지에 맞는 크기가 있습니까?

+2

** ImageView에 ** 아무 것도 넣을 수 없습니다 **. ** 무언가를 ** 털어 놓을 수 있습니다. 그러나 이미지를 뷰의 배경으로 넣을 수 있습니다. EditText 포함. "올바른 크기"에 대해서는 대신 9 개의 패치를 사용합니다. –

+0

유일한 방법은 예를 들어 Photoshop을 사용하여 이미지 크기를 조정하는 것입니다. – ste9206

+1

9 패치를 사용하지 않는 이유는 무엇입니까? –

답변

0

나는 라고 생각합니다. 질문을 올바르게 이해하고 있습니다. EditText를 배경 이미지의 테두리로 밀기를 원한다고 생각합니다. 예를 들어, 나는 단지 EditText 주위에 10dp 여백을 두었습니다. 희망이 도움이!

<!--Adjust with dimensions for the dimensions of the container and image view--> 
<FrameLayout 
    android:layout_width="297dp" 
    android:layout_height="199dp"> 

    <ImageView 
     android:id="@+id/background" 
     android:layout_width="297dp" 
     android:layout_height="199dp" 
     android:src="@drawable/photoframe"/> 

    <!--Adjust margins as you see fit--> 
    <EditText 
     android:id="@+id/edit_text" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginStart="10dp" 
     android:layout_marginEnd="10dp" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="10dp" 
     android:background="#000"/> 

</FrameLayout> 

그런 다음 프레임 레이아웃을 필요에 따라 레이아웃 어딘가에 삽입합니다. 또한 다음과 같이하십시오. 픽셀 크기는 장치에 따라 다르며 고밀도 디스플레이의 경우 모든 픽셀 밀도에 대한 이미지가없는 경우 이미지 저하가 발생합니다.

관련 문제