Отображение сложного списка в Android - PullRequest
0 голосов
/ 27 ноября 2011

Я работаю над проектом Android, для которого требуется ListView, например: enter image description here

Каждая строка состоит из трех частей с разными шрифтами и выравниваниями.Если честно, я изучил много идей, но не получилось.Ваше руководство и помощь будут высоко оценены.

С уважением.


КОД


CategoryActivity.java

ArrayList<HashMap<String,String>> list = 
                new ArrayList<HashMap<String,String>>(); 

public class CategoryActivity extends ListActivity 
{

  public void onCreate(Bundle savedInstanceState)
    {


        super.onCreate(savedInstanceState);


        setContentView(R.layout.category);

        list.clear();
         SimpleAdapter adapter = new SimpleAdapter(
                    this,
                    list,
                    R.layout.custom_row_view,
                    new String[] {"contents"},
                    new int[] {R.id.text1}
                    );
            populateList();
            setListAdapter(adapter);


    }

 private void populateList() 
    {
        HashMap<String,String> temp;
        for(int i=0;i<contents.length;i++)
        {
            temp = new HashMap<String,String>();
            temp.put("contents", contents[i]);
            temp.put("str", str[i]);
            temp.put("counts", counts[i]+"");
            list.add(temp);
        }

    }
.

.
.
}

custom_row_view.xml

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

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="fill_parent"
        android:layout_height="fill_parent"

        android:stretchColumns="0"
         android:background="#00000000"
    >

    <TableRow>


         <TextView
        android:id="@+id/text1"
        android:textColor="#FF0000"   
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_gravity="right"
        android:textSize="30px"
         android:paddingRight="10dip" 
        >
    </TextView>


<TextView android:id="@+id/text1"         
    android:textColor="#FF0000"   
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"


    android:layout_gravity="right" />       



    </TableRow>


  </TableLayout>



</LinearLayout>

И, наконец, category.xml

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



 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mylayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


        <ListView 
        android:id="@id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000fff"
    android:layout_weight="2"
    android:drawSelectorOnTop="false">
    </ListView>

</FrameLayout>


</LinearLayout>

На самом деле приведенный выше код не реализует то, что показывает картинка, но это так близко к тому, что яиспользуемый.Ваши предложения приветствуются.

Ответы [ 2 ]

0 голосов
/ 27 ноября 2011

Изменение шрифта на жирный шрифт может быть достигнуто в XML с помощью:

android:textStyle="bold"

или по коду:

.setTypeface(Typeface.BOLD);
0 голосов
/ 27 ноября 2011

Вам нужно будет создать собственный макет списка и свой собственный адаптер.Ищите «Учебник ListView»

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...