English 中文(简体)
同一版式中的列表视图和文本视图
原标题:Listview and textview in the same layout

In my application i have to display a listview and below to that i have to display a textview.Is it possible to have listview and textview in the same layout? My code is as follows:

  setContentView(R.layout.report);  
     ListView lv=(ListView)findViewById(R.id.listView1);
     db.open();
     Cursor c = db.getAllTitles();
     startManagingCursor(c);    
     String[] from = new String[] { db.KEY_INCOME,db.KEY_DESC};
     int[] to = new int[] { R.id.textView1 ,R.id.textView2};
     SimpleCursorAdapter notes =
                new SimpleCursorAdapter(this, R.layout.report, c, from, to);
//     System.out.println("notes="+notes.getCount());
     lv.setAdapter(notes);
    String total=  db.add();   

实际上,我正在显示两个文本视图以显示列表中的数据,最后我必须添加第三个文本视图以显示全线,如果我放相对版式的话,这个列表视图将适当地压倒另一个。 我的 Xml 文件如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >   

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   />
<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   /> 
<ListView
    android:id="@+id/listView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"        
    >
</ListView>  

谁来帮帮我,谢谢你们

问题回答

是可能的, 但当列表大小超过屏幕高度时, 您将永远无法看到文本视图 。 因此, 您将无法将视图添加到 LinearLayout 中, 而不是将这些视图添加到相对Layout 中, 设置 ListView 高度以填充父版, 并在文本视图上方 。 以及 TextView 在父版底端的对齐 。

您可以在屏幕底部设置文本视图, 列表视图在屏幕顶部和底部文本视图之间将全部空间移到列表视图上

此布局应该发挥以下技巧 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">  

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_above="@id/textView1"/>
</RelativeLayout>

是, 您可以在 Listview 下面使用 Textview 给某些挂贴, 使用 < 坚固 > Layout 边底 列表view 将您的 Textview 添加到 Listview 下。 因此, 为此使用 < 坚固 > RelativeLayout

使用线性布局代替 Reelititralay 并设置方向为“ 垂直 ”

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > 

<your textview/>
<your textview/>   

<your listview/>
<your textview with proper id/>

</LinearLayout>




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签