设计Android UI

时间:2019-07-12 09:41:37

标签: android android-studio android-layout

在设计新的Android应用程序时需要一些帮助。您能告诉我如何设计标记区域中的编辑文本吗?

enter image description here

3 个答案:

答案 0 :(得分:0)

请检查此

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/background_light">

<ImageView
        android:id="@+id/imagev"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"
        android:layout_margin="8dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"/>

<EditText android:layout_width="0dp"
          android:layout_height="0dp"
          android:layout_marginStart="8dp"
          android:layout_marginEnd="8dp"
          android:textSize="18sp"
          app:layout_constraintTop_toTopOf="@id/imagev"
          app:layout_constraintBottom_toBottomOf="@+id/imagev"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toEndOf="@id/imagev"
          android:hint="Hello World"
          android:background="@android:color/transparent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

答案 1 :(得分:0)

添加依赖项:

implementation 'com.google.android.material:material:1.0.0'

将主题更改为:

<style name="AppTheme" parent="Theme.MaterialComponents">

您可以轻松地做到这一点:

<com.google.android.material.textfield.TextInputLayout
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/label"
            app:errorEnabled="true"
            app:startIconDrawable="@drawable/ic_you_icon">

            <com.google.android.material.textfield.TextInputEditText
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>

答案 2 :(得分:0)

您可以使用可绘制对象添加底部边框,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:padding="5dp"
 android:background="@drawable/line_horizontal">

  <ImageView
    android:id="@+id/imagev"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@mipmap/ic_launcher"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent"/>

  <EditText android:layout_width="0dp"
    android:layout_height="0dp"
    android:textSize="18sp"
    android:padding="5dp"
    app:layout_constraintTop_toTopOf="@id/imagev"
    app:layout_constraintBottom_toBottomOf="@+id/imagev"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@id/imagev"
    android:hint="Hello World"
    android:background="@android:color/transparent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

<?xml version="1.0" encoding="utf-8"?>

line_horizo​​ntal

<item android:top="-10dp" android:left="-10dp" android:right="-10dp" android:bottom="1dp">
    <shape
        android:shape="rectangle">
        <stroke android:width="1dp" android:color="#000" />
        <solid android:color="#00000000" />
    </shape>
</item>