2016-10-12 2 views
-3

코드, 레이아웃은 레이아웃이

listView.setAdapter(new BaseAdapter() { 
     @Override 
     public int getCount() { 
      return 10; 
     } 

     @Override 
     public Object getItem(int position) { 
      return null; 
     } 

     @Override 
     public long getItemId(int position) { 
      return 0; 
     } 

     @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      convertView=getActivity().getLayoutInflater().inflate(R.layout.fragment_my_auto_adap,parent,false); 
      return convertView; 
     } 
    }); 

레이아웃

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.v7.widget.CardView 
    android:layout_height="100dp" 
    tools:layout_constraintTop_creator="1" 
    tools:layout_constraintRight_creator="1" 
    android:layout_marginStart="10dp" 
    android:layout_marginEnd="10dp" 
    app:layout_constraintRight_toRightOf="parent" 
    android:layout_marginTop="10dp" 
    tools:layout_constraintLeft_creator="1" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:id="@+id/cardView" 
    android:layout_width="match_parent"> 

    <android.support.constraint.ConstraintLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <ImageView 
      android:layout_width="64dp" 
      android:layout_height="64dp" 
      app:srcCompat="@drawable/car_item_r" 
      android:id="@+id/imageView" 
      android:adjustViewBounds="true" 
      android:layout_marginStart="16dp" 
      app:layout_constraintLeft_toLeftOf="parent" 
      android:layout_marginLeft="16dp" 
      android:layout_marginTop="16dp" 
      app:layout_constraintTop_toTopOf="parent"/> 

     <TextView 
      android:layout_height="0dp" 
      android:id="@+id/line" 
      android:layout_marginStart="8dp" 
      app:layout_constraintLeft_toRightOf="@+id/imageView" 
      android:layout_marginLeft="8dp" 
      app:layout_constraintTop_toTopOf="@+id/imageView" 
      app:layout_constraintBottom_toBottomOf="@+id/imageView" 
      android:background="#F38C8D" 
      android:layout_width="1dp"/> 

     <TextView 
      android:text="Nisan Teana" 
      android:layout_width="wrap_content" 
      android:layout_height="17dp" 
      android:id="@+id/textViewName" 
      app:layout_constraintBottom_toBottomOf="@+id/imageView" 
      app:layout_constraintTop_toTopOf="@+id/imageView" 
      app:layout_constraintLeft_toRightOf="@+id/line" 
      android:layout_marginStart="5dp" 
      android:layout_marginLeft="5dp"/> 

     <ImageView 
      android:layout_height="wrap_content" 
      app:srcCompat="@drawable/chat" 
      android:id="@+id/imageView3" 
      android:adjustViewBounds="true" 
      tools:layout_editor_absoluteY="16dp" 
      android:layout_marginEnd="32dp" 
      app:layout_constraintRight_toRightOf="parent" 
      android:layout_marginRight="32dp" 
      android:layout_width="48dp"/> 

     <TextView 
      android:text="Лайкнуть кампанию" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/textView2" 
      android:textSize="8sp" 
      app:layout_constraintTop_toBottomOf="@+id/imageView3" 
      app:layout_constraintBottom_toBottomOf="parent" 
      android:layout_marginBottom="16dp" 
      app:layout_constraintRight_toRightOf="@+id/imageView3" 
      app:layout_constraintLeft_toLeftOf="@+id/imageView3"/> 

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

결과

enter image description here

올바르게 표시되지 않습니다 제대로 표시되지 않습니다.
제대로 작동하려면 어떻게해야합니까?

RelativeLayout을 사용하면 모든 것이 작동합니다.
무엇이 잘못 되었나요? 난 이해가 안 돼요.

답변

0

안드로이드 스튜디오는 이미지 뷰에 당신에게 확실히 이해할 수있는 오류 메시지를 제공합니다 이 enter image description here

그래서, 수직 제약 조건을 추가 할 수 있습니다.

app:layout_constraintTop_toTopOf="parent" 
app:layout_constraintBottom_toBottomOf="parent" 
+0

Beloo Thx. 이게 효과적이야.) – TestAndroid

관련 문제