设置列表视图大小 Android

发布于 2024-08-25 14:20:15 字数 6431 浏览 6 评论 0原文

我在我的项目中使用列表视图,其中使用了一个用于创建列表项的 xml 文件。然后我在我的类中以编程方式使用了它,该类由 ListActivity 扩展。 但问题是我必须在屏幕底部添加一个按钮,该按钮与列表视图无关,但列表视图覆盖了整个屏幕。 那么,有没有什么方法可以在 android 中的列表视图底部添加按钮。

我的代码是:-

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

public class Options extends ListActivity {
    String[] items;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        requestWindowFeature(Window.FEATURE_RIGHT_ICON);

        items = getResources().getStringArray(R.array.chantOption_array);
        setListAdapter(new IconicAdapter());
        ListView lv = getListView();
        lv.setTextFilterEnabled(true);
        lv.setBackgroundResource(R.drawable.ichant_logo);
        setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON, R.drawable.icon_t);


        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // When clicked, show a toast with the TextView text

                Toast.makeText(getApplicationContext(),
                        items[position], Toast.LENGTH_SHORT).show();


                if ("Gayatri Mantra".equals(items[position].toString())) {
                    int[] timeintervals = { 23900, 24000 };
                    // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio)
                    startChantActivity(2, 108, R.drawable.gayatri,
                            R.raw.gayatri, R.drawable.icon_gayatri,
                            "Gayatri Mantra", timeintervals);
                }
                if ("Om Mani Padme Hum".equals(items[position].toString())) {
                    int[] timeintervals = { 5500, 8200, 11100, 13900, 34100,
                            36700, 39500, 42300, 59300, 62000, 64800, 67600,
                            124600 };

                    // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio)

                    startChantActivity(2, 108, R.drawable.ommanipadmehum,
                            R.raw.om_mani, R.drawable.icon_padme,
                            "Om Mani Padme Hum", timeintervals);

                }
                if ("Sai Ram".equals(items[position].toString())) {

                    // Audio time interval for bead+total time duration of audio
                    int[] timeintervals = { 4800, 7500, 10400, 12600, 15800,
                            18600, 21600, 24400, 25000 };
                    // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio)
                    startChantActivity(2, 108, R.drawable.sairam, R.raw.sairam,
                            R.drawable.icon_sairam, "Sai Ram", timeintervals);
                }
                if ("Aum".equals(items[position].toString())) {
                    // Audio time interval for bead+total time duration of audio
                    int[] timeintervals = { 12850, 13000 };

                    // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio)

                    startChantActivity(2, 108, R.drawable.aum, R.raw.aum,
                            R.drawable.ico_aum, "Aum", timeintervals);
                }





            }
        });

    }



    class IconicAdapter extends ArrayAdapter {
        IconicAdapter() {
            super(Options.this, R.layout.list_item, items);

        }

        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = getLayoutInflater();
            View row = inflater.inflate(R.layout.list_item, parent, false);
            TextView label = (TextView) row.findViewById(R.id.label);
            label.setText(" "+items[position]);
            ImageView icon = (ImageView) row.findViewById(R.id.icon);
            if (items[position].equals("Gayatri Mantra")) {
                icon.setImageResource(R.drawable.icon_gayatri);
            }
            if (items[position].equals("Om Mani Padme Hum")) {
                icon.setImageResource(R.drawable.icon_padme);
            }
            if (items[position].equals("Sai Ram")) {
                icon.setImageResource(R.drawable.icon_sairam);
            }
            if (items[position].equals("Aum")) {
                icon.setImageResource(R.drawable.ico_aum);
            }
            return (row);
        }
    }


    protected void startChantActivity(int mala_loop, int beads_loop,
            int background, int media, int titleIcon, String title,
            int[] timeintervals) {

        Bundle bundle = new Bundle();
        bundle.putInt("mala_loop", mala_loop);
        bundle.putInt("beads_loop", beads_loop);
        bundle.putInt("background", background);
        bundle.putInt("media", media);
        bundle.putInt("titleIcon", titleIcon);
        bundle.putString("title", title);
        bundle.putIntArray("intervals", timeintervals);
        Intent intent = new Intent(this, ChantBliss.class);
        intent.putExtras(bundle);
        startActivityForResult(intent, this.getSelectedItemPosition());

    }
}

相应的 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:orientation="horizontal"
>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:paddingLeft="2px"
android:paddingRight="2px"
android:paddingTop="2px"
android:layout_height="wrap_content"

/>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:textColor="#ff000000"

/>
</LinearLayout>

提前致谢: 桑迪普

I am using List View in my project where i have used a xml file which is used to create the list item.Then i have used it programmatically in my class which is extended by ListActivity.
But the problem is i have to add a button in the bottom of screen which is not related to list view but List view covers all the screen.
So,is there any way to add button in bottom with list view in android.

My Code is :-

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

public class Options extends ListActivity {
    String[] items;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        requestWindowFeature(Window.FEATURE_RIGHT_ICON);

        items = getResources().getStringArray(R.array.chantOption_array);
        setListAdapter(new IconicAdapter());
        ListView lv = getListView();
        lv.setTextFilterEnabled(true);
        lv.setBackgroundResource(R.drawable.ichant_logo);
        setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON, R.drawable.icon_t);


        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // When clicked, show a toast with the TextView text

                Toast.makeText(getApplicationContext(),
                        items[position], Toast.LENGTH_SHORT).show();


                if ("Gayatri Mantra".equals(items[position].toString())) {
                    int[] timeintervals = { 23900, 24000 };
                    // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio)
                    startChantActivity(2, 108, R.drawable.gayatri,
                            R.raw.gayatri, R.drawable.icon_gayatri,
                            "Gayatri Mantra", timeintervals);
                }
                if ("Om Mani Padme Hum".equals(items[position].toString())) {
                    int[] timeintervals = { 5500, 8200, 11100, 13900, 34100,
                            36700, 39500, 42300, 59300, 62000, 64800, 67600,
                            124600 };

                    // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio)

                    startChantActivity(2, 108, R.drawable.ommanipadmehum,
                            R.raw.om_mani, R.drawable.icon_padme,
                            "Om Mani Padme Hum", timeintervals);

                }
                if ("Sai Ram".equals(items[position].toString())) {

                    // Audio time interval for bead+total time duration of audio
                    int[] timeintervals = { 4800, 7500, 10400, 12600, 15800,
                            18600, 21600, 24400, 25000 };
                    // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio)
                    startChantActivity(2, 108, R.drawable.sairam, R.raw.sairam,
                            R.drawable.icon_sairam, "Sai Ram", timeintervals);
                }
                if ("Aum".equals(items[position].toString())) {
                    // Audio time interval for bead+total time duration of audio
                    int[] timeintervals = { 12850, 13000 };

                    // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio)

                    startChantActivity(2, 108, R.drawable.aum, R.raw.aum,
                            R.drawable.ico_aum, "Aum", timeintervals);
                }





            }
        });

    }



    class IconicAdapter extends ArrayAdapter {
        IconicAdapter() {
            super(Options.this, R.layout.list_item, items);

        }

        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = getLayoutInflater();
            View row = inflater.inflate(R.layout.list_item, parent, false);
            TextView label = (TextView) row.findViewById(R.id.label);
            label.setText(" "+items[position]);
            ImageView icon = (ImageView) row.findViewById(R.id.icon);
            if (items[position].equals("Gayatri Mantra")) {
                icon.setImageResource(R.drawable.icon_gayatri);
            }
            if (items[position].equals("Om Mani Padme Hum")) {
                icon.setImageResource(R.drawable.icon_padme);
            }
            if (items[position].equals("Sai Ram")) {
                icon.setImageResource(R.drawable.icon_sairam);
            }
            if (items[position].equals("Aum")) {
                icon.setImageResource(R.drawable.ico_aum);
            }
            return (row);
        }
    }


    protected void startChantActivity(int mala_loop, int beads_loop,
            int background, int media, int titleIcon, String title,
            int[] timeintervals) {

        Bundle bundle = new Bundle();
        bundle.putInt("mala_loop", mala_loop);
        bundle.putInt("beads_loop", beads_loop);
        bundle.putInt("background", background);
        bundle.putInt("media", media);
        bundle.putInt("titleIcon", titleIcon);
        bundle.putString("title", title);
        bundle.putIntArray("intervals", timeintervals);
        Intent intent = new Intent(this, ChantBliss.class);
        intent.putExtras(bundle);
        startActivityForResult(intent, this.getSelectedItemPosition());

    }
}

And Corresponding xml file is:

<?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:orientation="horizontal"
>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:paddingLeft="2px"
android:paddingRight="2px"
android:paddingTop="2px"
android:layout_height="wrap_content"

/>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:textColor="#ff000000"

/>
</LinearLayout>

Thanks in Advance:
Sandeep

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉风有信 2024-09-01 14:20:15

像这样的事情对我来说很有效:

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

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

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >
        <EditText
            android:id="@+id/newfilter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="Add a filter"

            />
        <Button
            android:id="@+id/addit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="fill_horizontal"
            android:drawableLeft="@drawable/btn_plus_pressed"
            />
    </LinearLayout>               
</LinearLayout>

Something like this did the trick for me:

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

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

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >
        <EditText
            android:id="@+id/newfilter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="Add a filter"

            />
        <Button
            android:id="@+id/addit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="fill_horizontal"
            android:drawableLeft="@drawable/btn_plus_pressed"
            />
    </LinearLayout>               
</LinearLayout>
寂寞美少年 2024-09-01 14:20:15

android:gravity="bottom|right"

来自:http://code.google.com/p/k9mail/source/browse/k9mail/trunk/res/layout/account_setup_basics.xml?r=1314

<RelativeLayout
        android:layout_marginTop="-45dip" 
        android:padding="0dip"
        android:layout_alignParentBottom="true"
        android:gravity="bottom|right" 
        android:background="@android:drawable/bottom_bar"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent">
        <Button
            android:id="@+id/manual_setup"
            android:text="@string/account_setup_basics_manual_setup_action"
            android:minWidth="@dimen/button_minWidth"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_marginBottom="-4dip" 
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="false" 
            />
        <Button
            android:id="@+id/next"
            android:text="@string/next_action"
            android:minWidth="@dimen/button_minWidth"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:drawableRight="@drawable/button_indicator_next"
            android:layout_marginBottom="-4dip" 
            android:layout_alignParentRight="true"
            android:layout_centerVertical="false" 
            />
    </RelativeLayout>

编辑

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">
<ListView ............... />
<!-- then my RelativeLayout -->
<RelativeLayout .............. />
</LinearLayout>

android:gravity="bottom|right"

From: http://code.google.com/p/k9mail/source/browse/k9mail/trunk/res/layout/account_setup_basics.xml?r=1314

<RelativeLayout
        android:layout_marginTop="-45dip" 
        android:padding="0dip"
        android:layout_alignParentBottom="true"
        android:gravity="bottom|right" 
        android:background="@android:drawable/bottom_bar"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent">
        <Button
            android:id="@+id/manual_setup"
            android:text="@string/account_setup_basics_manual_setup_action"
            android:minWidth="@dimen/button_minWidth"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_marginBottom="-4dip" 
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="false" 
            />
        <Button
            android:id="@+id/next"
            android:text="@string/next_action"
            android:minWidth="@dimen/button_minWidth"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:drawableRight="@drawable/button_indicator_next"
            android:layout_marginBottom="-4dip" 
            android:layout_alignParentRight="true"
            android:layout_centerVertical="false" 
            />
    </RelativeLayout>

EDIT

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">
<ListView ............... />
<!-- then my RelativeLayout -->
<RelativeLayout .............. />
</LinearLayout>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文