2017-01-17 4 views
0

Это активность входа, которую я хочу достичь в моем приложении (Image2). Но я не знаю, как это сделать, потому что я не могу вставить editText, пароль и кнопка над белой частью изображения (все изображение имеет черную рамку). Приложение имеет белый фон, и я хочу сделать вид изображения кривой и поместить под него другие поля. На данный момент это выглядит как image1.Вставить текстовое поле и кнопку над ImageView в LinearLayout

enter image description here

и посмотреть этот

enter image description here

Я также хочу, чтобы мое изображение, чтобы привести в соответствие с нижней и его ширины, чтобы быть match_parent и высоты, чтобы быть отрегулирована таким образом, чтобы соотношение из оригинальное изображение сохраняется на разных устройствах. Вот мой XML-код:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    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:id="@+id/banner" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="5" 
    tools:context="com.example.android.start.MainActivity"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     app:srcCompat="@drawable/logo" 
     android:id="@+id/logo" 
     android:layout_weight="2" 
    /> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="3" 
     android:id="@+id/back" 
     app:srcCompat="@drawable/image2" 

    /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="textPassword" 
     android:ems="10" 
     android:id="@+id/editText3" /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="textPersonName" 
     android:text="Name" 
     android:ems="10" 
     android:id="@+id/editText2" /> 

    <Button 
     android:text="Button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/button" 
     android:layout_centerInParent="true"/> 


</LinearLayout> 
+2

Я думаю, что вы должны использовать FrameLayout – Piyush

+0

Используйте виджеты под RelativeLayout и установить изображение в качестве фона этого, ваша проблема будет решена. –

+0

используйте FrameLayout, и вы предоставите второе изображение в качестве второго фона FrameLayout. Затем добавьте текст редактирования с конкретным дополнением сверху –

ответ

0

Вот код, который я использовал, чтобы достигнуть взгляда от IMAGE2:

<LinearLayout 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:id="@+id/banner" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="5" 
    tools:context="com.example.android.start.MainActivity"> 

    <ImageView 
     android:id="@+id/logo" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="2" 
     app:srcCompat="@drawable/logo" /> 

    <FrameLayout 
     android:id="@+id/frame" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="3" 
     android:background="@drawable/back" 
     android:weightSum="2"> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <EditText 
       android:id="@+id/name" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:background="#C8E6C9" 
       android:ems="10" 
       android:hint="Username" 
       android:inputType="textPersonName" 
       android:layout_marginBottom="117dp" 
       android:layout_alignParentBottom="true" 
       android:layout_centerHorizontal="true" /> 

      <Button 
       android:id="@+id/button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_horizontal|center_vertical" 
       android:text="Sign In" 
       android:background="#8BC34A" 
       android:layout_alignParentBottom="true" 
       android:layout_centerHorizontal="true" 
       android:layout_marginBottom="11dp" /> 

      <EditText 
       android:id="@+id/password" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom" 
       android:background="#C8E6C9" 
       android:ems="10" 
       android:hint="Password" 
       android:inputType="textPassword" 
       android:layout_above="@+id/button" 
       android:layout_alignLeft="@+id/name" 
       android:layout_alignStart="@+id/name" 
       android:layout_marginBottom="19dp" /> 
      /> 

     </RelativeLayout> 

    </FrameLayout> 
</LinearLayout> 
0

Вы можете сделать что-то вроде этого

<LinearLayout 
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:id="@+id/banner" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:weightSum="5" 
tools:context="com.example.android.start.MainActivity"> 

<ImageView 
    android:id="@+id/logo" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="2" 
    app:srcCompat="@drawable/logo" 
    /> 

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="3" 
    android:gravity="center" 
    app:srcCompat="@drawable/image2"> 


    <EditText 
     android:id="@+id/editText3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:ems="10" 
     android:inputType="textPassword"/> 

    <EditText 
     android:id="@+id/editText2" 

     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:inputType="textPersonName" 
     android:text="Name"/> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:text="Button"/> 

</LinearLayout> 

+0

Спасибо, но это не сработало. Мне удалось решить мою проблему с помощью FrameLayout. – Victoria

0

Использование RelativeLayout вместо LinearLayout это будет, мы надеемся решить вашу проблему.

Смежные вопросы