2017-12-09 2 views
0

맞춤식 목록보기에 대해 배우기 위해 앱을 코딩했습니다. 앱에 오류가 없지만 하나의 문제가 있습니다. 나는 다음과 같이 그것을 이미지에 나타냈다. IMAGE 1 IMAGE 2맞춤 목록 특정 화면 높이에 대해 하나의 항목보기

문제는 내가이 문제를 해결하려면 other.How 아래 하나가 표시되지 않습니다 다음 목록 item.The 목록 항목을 찾을 수 있습니다 전에 먼 길을 이동해야입니까?

package com.example.hp.customlistview; 

import android.support.constraint.ConstraintLayout; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.BaseAdapter; 
import android.widget.ImageView; 
import android.widget.ListView; 
import android.widget.TextView; 

public class MainActivity extends AppCompatActivity { 

    int IMAGES[]={R.drawable.adsense, R.drawable.allo, R.drawable.chrome, R.drawable.firebase, R.drawable.youtube}; 
    String[] NAMES={"AdSense","Allo","Chrome","Firebase","YouTube"}; 
    String [] DESCRIPTIONS={"Money through ads","Video calling","Web Browser","Cloud Database","Video Streaming"}; 
    private ListView listView; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     listView=(ListView)findViewById(R.id.listView); 
     CustomAdapter customAdapter=new CustomAdapter(); 
     listView.setAdapter(customAdapter); 
    } 

    class CustomAdapter extends BaseAdapter{ 

     @Override 
     public int getCount() { 
      Log.d("Length of Array ","The length is "+IMAGES.length); 
      return IMAGES.length; 
     } 

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

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

     @Override 
     public View getView(int i, View view, ViewGroup viewGroup) { 
      LayoutInflater layoutInflater=(LayoutInflater)getApplicationContext().getSystemService(getApplicationContext().LAYOUT_INFLATER_SERVICE); 
      view=layoutInflater.inflate(R.layout.customlayout, null); 
      Log.d("Image ID","The id is "+R.id.imageView); 
      ImageView imageView=(ImageView)view.findViewById(R.id.imageView); 
      TextView textView_name=(TextView)view.findViewById(R.id.textView); 
      TextView textView_desc=(TextView)view.findViewById(R.id.textView2); 
      if(imageView==null) 
       Log.d("NULL?","YES IT IS NULL"); 
      else 
       Log.d("NULL?","NO IT IS NOT NULL"); 
      imageView.setImageResource(IMAGES[i]); 
      textView_name.setText(NAMES[i]); 
      textView_desc.setText(DESCRIPTIONS[i]); 
      Log.d("Hello","Hello there "+textView_name.getText().toString()); 
      return view; 
     } 
    } 
} 

customlayout.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.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="120dp"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="86dp" 
     android:layout_height="91dp" 
     android:layout_marginBottom="8dp" 
     android:layout_marginStart="32dp" 
     android:layout_marginTop="16dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintVertical_bias="0.0" 
     app:srcCompat="@mipmap/ic_launcher" /> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="161dp" 
     android:layout_height="39dp" 
     android:layout_marginBottom="8dp" 
     android:layout_marginStart="28dp" 
     android:layout_marginTop="24dp" 
     app:layout_constraintBottom_toTopOf="@+id/textView2" 
     app:layout_constraintStart_toEndOf="@+id/imageView" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintVertical_bias="0.0" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="237dp" 
     android:layout_height="57dp" 
     android:layout_marginBottom="380dp" 
     android:layout_marginEnd="8dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginStart="44dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintHorizontal_bias="1.0" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintStart_toEndOf="@+id/imageView" /> 

    <CheckBox 
     android:id="@+id/checkBox" 
     android:layout_width="39dp" 
     android:layout_height="39dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="16dp" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintStart_toEndOf="@+id/textView" 
     app:layout_constraintTop_toTopOf="parent" /> 
</android.support.constraint.ConstraintLayout> 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.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" 
    tools:context="com.example.hp.customlistview.MainActivity"> 

    <ListView 
     android:id="@+id/listView" 
     android:layout_width="386dp" 
     android:layout_height="409dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="24dp" 
     android:text="Ok" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/listView" /> 
</android.support.constraint.ConstraintLayout> 

이 문제를 해결하려면, 나는 다음과 같은

1) 안드로이드를 시도 : layout_height 다음은 내 코드입니다 = "match_parent"를 120 dp의 특정 높이로 설정하십시오. (그것은 customlayout.xml에) 그러나

2)와 같은 절대 및 상대 레이아웃 같은 다른 레이아웃을 사용 작동하지 않았다,하지만 이미지가 많이 예상 크기

EDIT를 넘어 목록의 컨텐츠를 채우는 : 아래의 설명에서 Ben P.의 제안을받은 후 목록 항목이 압축 방식으로 표시됩니다 ( ). IMAGE 3 그러나 MainActivity.java에서 프로그램 적으로 설정 했음에도 불구하고 설명이 나타나지 않습니다. android : layout_height를 사용자 정의 값으로 설정하면 설명 텍스트보기가 미리보기에서 사라집니다.

누군가가 downvoting 경우, 그렇게 이유를 알려주십시오. 이것은 내 질문의 질을 높이는 데 도움이 될 것입니다.

+0

당신은 확실히'customlayout 높이에 대한 match_parent'을 사용하지 않으 :)입니다 각 항목은 목록보기 자체와 동일한 높이가됩니다. 고정 높이 또는'wrap_content'를 사용해야합니다. –

+0

이 방법으로 문제를 해결할 수 있을지는 모르겠지만 customlayout을 부 풀릴 때는 부모 호출을 사용해야합니다. 'view = layoutInflater.inflate (R.layout.customlayout, viewGroup, false);' –

+0

리스트 뷰와 커스텀 레이아웃의 뷰에'wrap_content'를 사용하십시오. 희망이 도움이됩니다. – Chithra

답변

0

좋아, 알아 냈어. 앞으로 비슷한 의구심을 갖는 사람을 위해 게시하십시오. 항목을 드래그 앤 드롭하기 전에 레이아웃 높이를 120dp 또는 일부 유한 값으로 설정합니다. 이제 축소 된 레이아웃에서 드래그 앤 드롭 작업을 시작하십시오. 꽤 간단합니다. 이것으로 해결할 수있었습니다. 는 여기가

Image 5

관련 문제