1

我正在列表视图下方的脚栏中寻找选项卡类型的按钮,但这没有发生。在这里,我向您展示了两种布局,一种具有 Tab Bar,另一种具有 ListView。我不确定我应该在哪个布局中添加按钮以将其放在脚栏中下面是我的列表视图代码和快照:

标签栏.xml

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>

</TabHost>

列表项选择.xml

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

    <include
        android:id="@+id/list_item_section_text"
        layout="@android:layout/preference_category" />

</LinearLayout>

列表视图.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="wrap_content"
    android:gravity="center_vertical"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:paddingRight="?android:attr/scrollbarSize" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="6dip"
        android:layout_marginLeft="0dip"
        android:layout_marginRight="6dip"
        android:layout_marginTop="6dip"
        android:layout_weight="0">

        <TextView
            android:id="@+id/list_item_entry_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/list_item_entry_summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@id/list_item_entry_title"
            android:layout_below="@id/list_item_entry_title"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary" />
    </RelativeLayout>
</LinearLayout>

列表视图.java

public class TestListView extends ListActivity {
    /** Called when the activity is first created. */

     ArrayList<Item> items = new ArrayList<Item>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



    items.add(new SectionItem("Category 1"));
    items.add(new EntryItem("Item 1", "This is item 1.1"));
    items.add(new EntryItem("Item 2", "This is item 1.2"));
    items.add(new EntryItem("Item 3", "This is item 1.3"));


    items.add(new SectionItem("Category 2"));
    items.add(new EntryItem("Item 4", "This is item 2.1"));
    items.add(new EntryItem("Item 5", "This is item 2.2"));
    items.add(new EntryItem("Item 6", "This is item 2.3"));
    items.add(new EntryItem("Item 7", "This is item 2.4"));

    items.add(new SectionItem("Category 3"));
    items.add(new EntryItem("Item 8", "This is item 3.1"));
    items.add(new EntryItem("Item 9", "This is item 3.2"));
    items.add(new EntryItem("Item 10", "This is item 3.3"));
    items.add(new EntryItem("Item 11", "This is item 3.4"));
    items.add(new EntryItem("Item 12", "This is item 3.5"));

    EntryAdapter adapter = new EntryAdapter(this, items);


        EntryAdapter adapter = new EntryAdapter(this, items);

        setListAdapter(adapter);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {

        if(!items.get(position).isSection()) {

            EntryItem item = (EntryItem)items.get(position);
            Toast.makeText(this, "You clicked " + item.title , Toast.LENGTH_SHORT).show();

        }

        super.onListItemClick(l, v, position, id);
    }
}

标签栏.java

public class Support extends TabActivity {

    //private ImageView mSpinnerImage = null;
    //private Animation mAnimation = null;
    private Button button = null;
    private TextView synctitle = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

            /*Titlebar + Button*/
            requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
            setContentView(R.layout.support);
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
            button  = (Button) findViewById(R.id.syncbutton);
            //mSpinnerImage = (ImageView) findViewById(R.id.spinner_view);
            //mAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate_animation);
            //synctitle  = (TextView) findViewById(R.id.synctitle);
            button.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                     // TODO Auto-generated method stub
                     //button.setVisibility(View.INVISIBLE);
                     //mSpinnerImage.setVisibility(View.VISIBLE);
                     //synctitle.setVisibility(View.VISIBLE);
                     //mSpinnerImage.setAnimation(mAnimation);
                     //mSpinnerImage.startAnimation(mAnimation);
                }
            });
            /*Titlebar + Button ends*/

            /*Tabs*/
            Bundle bundle = getIntent().getExtras();
            TabHost tabHost = getTabHost();
            TabHost.TabSpec spec;
            Intent intent;

            intent = new Intent().setClass(this, TestListView.class);
            spec = tabHost  .newTabSpec("some_things")
                            .setIndicator("Info")
                            .setContent(intent);
            tabHost.addTab(spec);

            intent = new Intent().setClass(this, TestListView.class);
            spec = tabHost  .newTabSpec("top_things")
                            .setIndicator("Log")
                            .setContent(intent);
            tabHost.addTab(spec);


            //tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 85;
            //tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 85;
            /*Tabs ends*/
    }
}
4

2 回答 2

2

要创建页脚按钮,首先创建一个 xml 文件

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

    <Button
        android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Footer Button" />

</RelativeLayout>

现在在你的活动的 OnCreate 方法中写下这个

LayoutInflater inflater = LayoutInflater.from(this);

View v = inflater.inflate(R.layout.button, null);

Button footer = (Button) v.findViewById(R.id.footer);

lv.addFooterView(v);  // use getListView() instead of lv if you are using ListActivity

更新

不要使用ListActivity而是使用Activity

首先创建一个xml文件

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

    <ListView
        android:id="@+id/listview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <Button
        android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Footer Button"
        android:layout_alignParentBottom="true" />

 </RelativeLayout>

现在在 onCreate extendsActivity并写下几行

setContentView(R.layout.listxml); 

在 super.onCreate(bundle) 之后;

于 2013-10-31T09:58:31.750 回答
1

尝试这个

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/LinearLayout2"
        android:background="#E7EFFA"
        android:gravity="center_horizontal" >

        <TextView
            android:id="@+id/txtLesson"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#E7EFFA"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/txtAmount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.30"
            android:background="#E7EFFA"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#ff0000" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bbar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="10dp"
        android:background="#E7EFFA"
        android:gravity="center_vertical|center_horizontal" >

        <Button
            android:id="@+id/button"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:background="@drawable/buy_button"
            android:minHeight="55dip"
            android:minWidth="55dip"
            android:paddingBottom="5dip"
            android:paddingTop="10dip"
            android:text="@string/PayButton"
            android:textColor="#FFFFFF"
            android:textSize="20sp" />
    </LinearLayout>

    <ListView
        android:id="@+id/lessonListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
         android:layout_above="@+id/bbar"
          android:layout_below="@+id/linearLayout1"
        android:background="#E7EFFA" >

    </ListView>

</RelativeLayout>
于 2013-10-31T10:17:48.907 回答