>

xml의 ImageView 옆에 TextView를 만들려면 어떻게해야합니까? 최선을 다했지만 여전히 만들 수는 없습니다.

이것처럼 : 디스플레이 프레임

제목과 설명이 포함 된 4 개의 텍스트가 필요합니다. 텍스트는 이미지를 설명하기위한 것이며, 어떤 조언이나 도움을 주시면 감사하겠습니다

이것은 내 XML 코드입니다 (지저분한 레이아웃을 얻습니다)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:background="@android:color/white"
    android:padding="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/img_item_photo"
        android:layout_width="150dp"
        android:layout_height="200dp"
        android:layout_marginEnd="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:src="@drawable/oneplus_7_pro_r1" />
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_toEndOf="@id/img_item_photo"
    android:layout_toRightOf="@id/img_item_photo"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/tv_item_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="165dp"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:text="@string/Hape_name"
        android:textSize="16sp"
        android:textStyle="bold" />
    <TextView
        android:id="@+id/tv_item_Desc"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/activity_horizontal_margin" />
 </LinearLayout>
</RelativeLayout>


  • 답변 # 1

    ConstraintLayout을 사용하여이보기를 간단하게 수행 할 수 있으며 아래 이미지와 같으며 XML을 다음과 같이 게시했습니다.

    작은 메모 :AndroidX가 여기에 사용됩니다.androidX에 익숙하지 않은 경우androidX에 대해 약간의 휴식을 취한 후 시도해보십시오.

    AndroidX가 아닌 지원 라이브러리를 사용하는 경우 교체 androidx.constraintlayout.widget.ConstraintLayout   android.support.constraint.ConstraintLayout 와 함께  아래 코드에서

    <?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"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white">
            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:srcCompat="@tools:sample/avatars" />
            <TextView
                android:id="@+id/tv_1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin_8dp"
                android:text="textView 1"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                android:textColor="@color/black"
                app:layout_constraintBottom_toTopOf="@id/tv_2"
                app:layout_constraintStart_toEndOf="@id/imageView1"
                app:layout_constraintTop_toTopOf="@id/imageView1" />
            <TextView
                android:id="@+id/tv_2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin_8dp"
                android:text="textView 2"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                android:textColor="@color/black"
                app:layout_constraintBottom_toTopOf="@id/tv_3"
                app:layout_constraintStart_toEndOf="@id/imageView1"
                app:layout_constraintTop_toBottomOf="@id/tv_1" />
            <TextView
                android:id="@+id/tv_3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin_8dp"
                android:text="textView 3"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                android:textColor="@color/black"
                app:layout_constraintBottom_toTopOf="@id/tv_4"
                app:layout_constraintStart_toEndOf="@id/imageView1"
                app:layout_constraintTop_toBottomOf="@id/tv_2" />
            <TextView
                android:id="@+id/tv_4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin_8dp"
                android:text="textView 4"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                android:textColor="@color/black"
                app:layout_constraintBottom_toBottomOf="@id/imageView1"
                app:layout_constraintStart_toEndOf="@id/imageView1"
                app:layout_constraintTop_toBottomOf="@id/tv_3" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    
    

  • 답변 # 2

    android:layout_marginBottom="165dp" 만 제거 텍스트보기에서

    이것을 시도해보십시오

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:background="@android:color/white"
        android:layout_height="match_parent">
        <ImageView
            android:id="@+id/img_item_photo"
            android:layout_width="150dp"
            android:layout_height="200dp"
            android:src="@drawable/ic_search_black" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_toEndOf="@id/img_item_photo"
            android:layout_toRightOf="@id/img_item_photo"
            android:orientation="vertical" >
            <TextView
                android:id="@+id/tv_item_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/load_available"
                android:textSize="16sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/tv_item_Desc"
                android:text="@string/load_available"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </RelativeLayout>
    
    

    또한 LinearLayout 와 함께 시도

    <?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"
        android:layout_width="match_parent"
        android:background="@android:color/white"
        android:orientation="horizontal"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/img_item_photo"
            android:layout_width="150dp"
            android:layout_height="200dp"
            android:src="@drawable/ic_search_black" />
        <LinearLayout
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/load_available"
                android:textSize="16sp"
                android:textStyle="bold" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/load_available"
                android:textSize="16sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/tv_item_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/load_available"
                android:textSize="16sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/tv_item_Desc"
                android:text="@string/load_available"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </LinearLayout>
    
    

  • 답변 # 3

    여기 해결책이 있습니다

    <?xml version="1.0" encoding="utf-8"?>
    
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:orientation="horizontal">
        <ImageView
            android:id="@+id/img_item_photo"
            android:layout_width="150dp"
            android:layout_height="200dp"
            android:layout_marginEnd="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin" />
        <LinearLayout
            android:id="+@id/layout_field"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:id="@+id/tv_item_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:text="Hape_name"
                android:textSize="16sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/tv_item_Desc"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/activity_horizontal_margin" />
        </LinearLayout>
    </LinearLayout>
    
    
    layout_field 내부에 더 많은 textView 추가 .

  • 답변 # 4

    약간의 개선으로 코드는 괜찮아 보이지만

    여기 다른 코드가 있습니다

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="@android:color/white"
    android:padding="@dimen/activity_vertical_margin"
    android:orientation="horizontal"
    android:layout_height="match_parent">
    <ImageView
        android:padding="10dp"
        android:layout_weight="1"
        android:id="@+id/img_item_photo"
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:src="@drawable/side_nav_bar" />
    <LinearLayout
        android:padding="10dp"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/tv_item_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Test"
            android:textSize="16sp"
            android:textStyle="bold" />
        <TextView
            android:id="@+id/tv_item_Desc"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Test 1"
            />
        <TextView
            android:id="@+id/tv_item_name1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Test"
            android:layout_marginTop="5dp"
            android:textSize="16sp"
            android:textStyle="bold" />
        <TextView
            android:id="@+id/tv_item_Desc2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Test 2"
            />
    </LinearLayout>
    
    

  • 이전 php - 내부 서버 오류 500 simplexml_load_file
  • 다음 javascript - rails/react 앱에서 API 호출 상태에 따라 내 뷰 업데이트