2015-08-31 3 views
0

Я хочу получить следующий макет в виде списка цитат.макет списка андроидов не в состоянии достичь

enter image description here

я пытаюсь на оранжевом фоне вместо серого и зеленого фона текста вместо белого:

следующее XML-

<?xml version="1.0" encoding="utf-8"?> 
<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gridview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:numColumns="1" 
    android:stretchMode="columnWidth" 
    android:gravity="center" 

/> 


the file quote_text.xml 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/holo_orange_dark" > 

    <TextView 
     android:id="@+id/quotetext1" 
     android:background="@android:color/holo_green_light" 
     android:layout_width="fill_parent" 
     android:layout_height="100dp" 
     android:paddingLeft="20dp" 
     android:layout_marginTop="15dp" 
     android:layout_marginBottom="15dp" 
     android:layout_marginLeft="15dp" 
     android:layout_marginRight="15dp" 
     android:paddingRight="20dp" 
     android:paddingTop="20dp" 
     android:paddingBottom="20dp" 
     android:textSize="15dp" > 
    </TextView> 

</LinearLayout> 

то, что я получаю следующее

result sanpshot

Мой код в GetView() является

public View getView(int position, View convertView, ViewGroup parent) { 
     TextView textView; 

    if (convertView == null) { 
     LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View gimkan = inflater.inflate(R.layout.quote_text, parent, false); 
     textView = (TextView) gimkan.findViewById(R.id.quotetext1); 
    } 
    else 
    { 
     textView = (TextView) convertView; 
    } 

    textView.setText(mThumbIds[position]); 
    return textView; 
} 

Я также попытался использовать следующие согласно ответу dieter_h

<?xml version="1.0" encoding="utf-8"?> 
<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gridview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
/> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:background="@android:color/holo_orange_dark"> 

<TextView 
    android:id="@+id/quotetext1" 
    android:background="@android:color/holo_green_light" 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    tools:text="kfjjkdshf jkhs jkdhs sdjh jksdh s sdjhfjksdh kjsdfh" 
    android:padding="20dp" 
    android:layout_margin="15dp" 
    android:textSize="15dp" /> 
</LinearLayout> 

Screenshot with listview

Все еще это показывает, как необходимо

ответ

0

Изменить ваши XML макеты для них:

ListView

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="16dp" 
    android:background="@android:color/holo_orange_dark"> 
    <ListView 
     android:id="@+id/listview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:dividerHeight="16dp" 
     android:divider="@android:color/transparent"/> 
</FrameLayout> 

ItemView

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="8dp" 
    android:background="@android:color/holo_green_dark" 
    android:textSize="14sp"/> 

И это то, что вы должны получить :

enter image description here

+0

У вас его есть. Почему мы должны использовать . Во многих местах я не искал его там, где упоминалось –

+0

Возможно, вы захотите использовать маржу для своего списка ListView на первом месте. НО, как и мой опыт, Android не учитывает поля, если в представлении с полями нет родителя, поэтому вы можете либо обернуть ListView с помощью «FrameLayout» (или любых унаследованных классов «ViewGroup», «LinearLayout», «RelativeLayout» ...), но «FrameLayout» - самый легкий в конце, поэтому я выбираю «FrameLayout»), затем установите для него дополнение или не установите дополнение для параметра «FrameLayout», но поля для ListView. Надеюсь, вы это получите;) – Leo

0

Попытка изменить quote_text.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:background="@android:color/holo_orange_dark"> 

<TextView 
    android:id="@+id/quotetext1" 
    android:background="@android:color/holo_green_light" 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    tools:text="kfjjkdshf jkhs jkdhs sdjh jksdh s sdjhfjksdh kjsdfh" 
    android:padding="20dp" 
    android:layout_margin="15dp" 
    android:textSize="15dp" /> 
</LinearLayout> 

Изменение GridView в ListView:

<?xml version="1.0" encoding="utf-8"?> 
<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gridview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 
+0

Это показывает то же самое снова. Весь зеленый цвет с текстом. Это как-то связано с 'View gimkan = inflater.inflate (R.layout.quote_text, parent, false);' –

+0

Я пробовал 'Просмотр gimkan = inflater.inflate (R.layout.quote_text, null)'. без изменений. его же (полный зеленый с текстом) –

+0

Без изменений в макете. Он показывает то же самое (зеленый экран с текстом). Он не показывает текст, который вы упомянули tools.text. он показывает текст из setText() –