设置列表视图大小 Android
我在我的项目中使用列表视图,其中使用了一个用于创建列表项的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的事情对我来说很有效:
Something like this did the trick for me:
android:gravity="bottom|right"
来自:http://code.google.com/p/k9mail/source/browse/k9mail/trunk/res/layout/account_setup_basics.xml?r=1314
编辑
android:gravity="bottom|right"
From: http://code.google.com/p/k9mail/source/browse/k9mail/trunk/res/layout/account_setup_basics.xml?r=1314
EDIT