2010-05-18 85 views
2

我listview.xml的Android的ListView TEXTSIZE

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:id="@+id/RelativeLayout01" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myapp="http://schemas.android.com/apk/res/zaid.quotes.dlama"> 
    <ListView android:id="@+id/ListView01" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_alignParentTop="true" 
     android:layout_marginBottom="50dp" android:paddingTop="50dp"></ListView> 
    <Button android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:id="@+id/Back" 
     android:layout_alignParentBottom="true" android:text="Go Back"></Button> 

    <LinearLayout android:layout_width="wrap_content" 
     android:id="@+id/LinearLayout01" android:layout_height="wrap_content" 
     android:layout_alignParentTop="true"> 
     <com.admob.android.ads.AdView android:id="@+id/ad" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF" 
      myapp:secondaryTextColor="#CCCCCC" android:layout_alignParentTop="true" /> 
    </LinearLayout> 


</RelativeLayout> 

在ListView文本的当前大小大。我似乎无法弄清楚如何改变文字大小。

+0

您是否使用自定义适配器来生成listview项目? – RoflcoptrException 2010-05-18 11:23:10

+0

你如何使用ListView和你正在使用的适配器? 如果你添加代码会更好。 – Karan 2010-05-18 11:23:40

+0

你是什么意思?它是否在屏幕外展开? – 2010-05-18 13:01:29

回答

2

我不知道如果我得到你想要的,但listView没有文本大小,它里面的元素是将定义他们的文本大小的元素。

也就是说,如果您向列表中添加文本视图,请在textView中定义文本大小。

3

真正重要的是这里的行ViewBaseAdaptergetView(..)CursorAdapternewView(..)返回。

您可以从Android来源复制simple_list_item_1.xmlsimple_list_item_2.xml并根据需要对其进行自定义。
说,改变
android:textAppearance="?android:attr/textAppearanceLarge"

android:textAppearance="?android:attr/textAppearanceMedium"

另一个选项是通过调用TextView上的setTextAppearance(context, android.R.attr.textAppearanceMedium)来更改Adapter中的文本外观。

0

我想你有错误的方法来使用ListView。使用适配器将列表提供给视图,并且在ListView布局文件中,您不定义行,您只定义列表视图本身和默认文本视图,该列表将在列表中没有项目时显示。然后你定义一个单独的XML文件,它将呈现每一行。然后在这行排版中,您可以随意设置文字大小。

这里的列表视图XML的例子(注意特殊ID的给予ListView和TextView的,这些都需要):

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

    <ListView android:id="@+id/android:list" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:layout_weight="1" 
     android:drawSelectorOnTop="false" /> 

    <TextView android:id="@+id/android:empty" 
     android:layout_width="fill_parent" android:layout_height="fill_parent" 
     android:text="No records found" /> 
</LinearLayout> 

然后你行布局将没有列表视图文件:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:id="@+id/RelativeLayout01" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myapp="http://schemas.android.com/apk/res/zaid.quotes.dlama"> 
    <Button android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:id="@+id/Back" 
     android:layout_alignParentBottom="true" android:text="Go Back"></Button> 

    <LinearLayout android:layout_width="wrap_content" 
     android:id="@+id/LinearLayout01" android:layout_height="wrap_content" 
     android:layout_alignParentTop="true"> 
     <com.admob.android.ads.AdView android:id="@+id/ad" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF" 
      myapp:secondaryTextColor="#CCCCCC" android:layout_alignParentTop="true" /> 
    </LinearLayout> 
</RelativeLayout> 

而这里的适配器的getView()方法的一个示例,您将设置行布局文件:

public View getView(int position, View convertView, ViewGroup parent) { 
     if (convertView == null) { 
      LayoutInflater inflater = (LayoutInflater) context 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = inflater.inflate(R.layout.row_layout, null); 
     } 
      //Now, assuming your adapter has the list of objects to be displayed in 'records': 
      if(records != null) { 
        YourRecord r = records.get(position); 
        if(r != null) { 
          // Populate your views in your row.xml based on data from your record selected (r) 
        } 
        ... 
      } 

} 
2

Yanchenko的回答可以完美运行,如果重命名你的本地simple_list_item_1.xml

MyActivity.java

ArrayAdapter<String> filesAdapter = new ArrayAdapter<String>(this, 
    R.layout.simplest_list_item_1, topFilesArray); 
filesList.setDivider(null); 

simplest_list_item_1.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textSize="7pt" 
    android:paddingLeft="6dip" /> 

layout_height="wrap_content"这里仅用于10列表项。