2016-08-11 3 views
0

Я пытаюсь получить простой пользовательский список View, и я поражен, как элементы прилипание друг к другу, который выглядит хуже, чем ever.I создали файл program_list.xml следующим образом:Почему они придерживаются друг друга?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="fill_horizontal|center_horizontal"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="1" 
    android:id="@+id/TVIDC" 
    android:layout_weight="1" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="Name" 
    android:id="@+id/TVNameC" 
    android:layout_weight="1" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="Date" 
    android:id="@+id/TVDateC" 
    android:layout_weight="1" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="0.00" 
    android:id="@+id/TVAmountC" 
    android:layout_weight="1" /> 
</LinearLayout> 

Это CustomList файл:

import android.app.Activity; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.TextView; 

public class CustomList extends ArrayAdapter<String> { 

private final Activity context; 
private final Integer[] id; 
private final String[] name; 
private final Integer[] amount; 
private final String[] date; 


public CustomList(Activity context, Integer[] id, String[] name, Integer[] amount, String[] date) { 
    super(context, R.layout.program_list, name); 
    this.context = context; 
    this.id = id; 
    this.name = name; 
    this.amount = amount; 
    this.date = date; 

} 

@Override 
public View getView(int position, View view, ViewGroup parent) { 
    LayoutInflater inflater = context.getLayoutInflater(); 
    View rowView = inflater.inflate(R.layout.program_list, null, true); 
    TextView txtId = (TextView) rowView.findViewById(R.id.TVIDC); 
    TextView txtName = (TextView) rowView.findViewById(R.id.TVNameC); 
    TextView txtAmount = (TextView) rowView.findViewById(R.id.TVAmountC); 
    TextView txtDate = (TextView) rowView.findViewById(R.id.TVDateC); 


    txtId.setText(id[position]+""); 
    txtName.setText(name[position]); 
    txtAmount.setText(amount[position]+""); 
    txtDate.setText(date[position]); 


    return rowView; 
} 
} 

Найти решение быстро, я поражаюсь, приложение загрузки хочет на игровом магазине и обратитесь к изображению для основной задачи. Спасибо всем заранее, и я должен написать некоторые глупые детали, чтобы удалить красную коробку, не думайте много об этом, потому что для публикации я должен удалить эту коробку. Тем не менее эта глупая коробка не исчезла. Эй, переполнение стека! Это сошло с ума.

Это вызывает проблему:

Its what coming

Но я хочу это:

Good one

+0

Измените ширину от wrapcontent до match_parent для всех TextView – MRX

+0

Не работает !! Предложите что-то еще ..... –

+0

Я не вносил никаких изменений в свой макет и сделал одну и ту же программу, используя ваш пользовательский адаптер, он отлично работает для меня – MRX

ответ

0

Изменение ширины ваших взглядов на android:layout_width="0dp". Кроме того, я не думаю, что вам нужна эта линия android:gravity="fill_horizontal|center_horizontal"

0

Сумма должна отсутствовать в родительском элементе LinearLayout.

Заменить

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="fill_horizontal|center_horizontal"> 

по

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="fill_horizontal|center_horizontal" 
android:weightSum="4"> 
Смежные вопросы