簡體   English   中英

是否可以在ListActivity中使用List以外的組件

[英]Is it possible to have components other than List in ListActivity

通過使用以下代碼。

BuyActivity.java

public class BuyActivity extends ListActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.transaction_list_view);        
        OrderAdapter orderAdapter = new OrderAdapter(this, 
            R.layout.custom_row_view, new ArrayList<Object>());
        setListAdapter(orderAdapter);        
        orderAdapter.add(new Object());
        orderAdapter.add(new Object());    
    }
}

transaction_list_view.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ListView android:id="@id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="2"
        android:drawSelectorOnTop="false">
    </ListView>
    <TextView android:id="@id/android:empty"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:text="No data"
    />  
</LinearLayout>

custom_row_view.xml

請參閱custom_row_view.xml

我得到了以下結果。

在此輸入圖像描述

除了列表,我還想在ListActivity的底部有一個靜態標簽。

我試試

transaction_list_view.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ListView android:id="@id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="2"
        android:drawSelectorOnTop="false">
    </ListView>
    <TextView android:id="@id/android:empty"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:text="No data"
    />
    <TextView
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:text="THIS IS TOTAL STATIC LABEL"
    />  
</LinearLayout>

但我得到了

在此輸入圖像描述

我的期望是什么

在此輸入圖像描述

有什么我錯過了嗎?

你已經指出你的ListView應該是垂直方向的fill_parent ,沒有空間容納你的其他小部件。 你的體重被忽略了。 您可能希望將android:layout_height改為0dip

嘗試將靜態textview的高度設置為wrap_content。

那么你可以嘗試相對布局來設置固定在屏幕底部的靜態標簽。 如果這不是你的意思,我會盡力幫助你。 祝好運

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM