-1

i have TextView and ListView on LinearLayout, unfortunately on small screen i have not enough space for ListView(i mean it display about 0.5row). Is it possible to scroll up everything together.? Is in SDK any alternative for ListView that i can use for it.? Or maybe You got other idea how to make it userfriendly.?

layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp" >

    <TextView
        android:id="@+id/textView5"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/studio"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

<ListView
    android:id="@+id/list_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="2" >
</ListView>
</LinearLayout>
4

4 回答 4

0
There is a better solution for this instead of adding title to the main layout you can add that title to another layout and inflate that layout as header to the listview.

Like this -:

LayoutInflater inflater = getLayoutInflater();
ViewGroup header = (ViewGroup)inflater.inflate(R.layout.title, myListView, false);
myListView.addHeaderView(header, null, false);

布局.xml

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

<ListView
    android:id="@+id/list_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</ListView>

</LinearLayout>


title.xml
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp" >

    <TextView
        android:id="@+id/textView5"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/studio"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>
于 2013-08-13T09:46:18.503 回答
0

LinearLayout带有 2TextView的 s 作为ListView使用addHeaderView的标题视图

于 2013-08-13T09:26:21.287 回答
0

您的问题是您分配给各种组件的尺寸和重量。为列表视图和文本视图布局分配适当的权重,它应该可以在任何屏幕上正常工作。例如做这样的事情:

    <LinearLayout 
          android:id= "@+id/parent_layout"
          android:layout_height = "match_parent"
          android:layout_width = "match_parent"
          android:weightSum = "1.0"
          android:orientation = "vertical" >

          <LinearLayout
             android:id= "@+id/text_views_layout"
             android:layout_height = "0dp"
             android:layout_width = "match_parent"
             android:layout_weight = "0.7" 
          >
              <!-- place your text views here -->

          </LinearLayout>

          <ListView
             android:id ="@+id/list"
             android:layout_height = "0dp"
             android:layout_width ="match_parent"
             android:layout_weight = "0.3" 
          >
          </ListView> 

   </LinearLayout> 

注意:您可以为 textview_layout 和 listview 指定任何权重比例(我已将其设置为 0.7:0.3),但请记住您分配给它们的权重,它们必须总计为父级的权重总和,即 1.0案子。否则,您可能会看到意外行为。

于 2013-08-13T09:03:24.167 回答
-1

ScrollView哪一个可以解决你的问题,例如

<ScrollView>
   <LinearLayout>
    ......
   //More code here

   </LinearLayout>

</ScrollView>

但请记住,Scroll View 只能有一个孩子,并且该孩子可以有自己的另一个孩子,但 ScrollView 只能有一个孩子。我的这段代码是为了让你知道它不能通过复制和粘贴来工作,你必须根据需要进行宽度、高度等调整

于 2013-08-13T07:31:34.890 回答