透明/朦胧的ListView的背景 - 我要摧毁的ListView活动上点击后台时 [英] Transparent/dim ListView background - I want to destroy ListView activity when clicking on background
问题描述
我有一个很好的运行的的ListView
列表。它的设置是这样的:
I have a ListView
list that operates nicely. It's set this way:
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true </item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
这是我的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:padding="0dp"
android:background="@drawable/button_pressed"
android:clickable="false"
android:id="@+id/ListViewLayout" >
<ImageView
android:id="@+id/logo"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp" />
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="30dp" >
</TextView>
</LinearLayout>
我也有code块创造我的的ListView
并处理点击次数:
public class RandomList extends ListActivity {
static final String[] randomList = new String[] {"Name 1", "Name 2", "Name 3", "Logo"};
@Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new RandomArrayAdapter(this, randomList));
}
protected void onListItemClick(ListView l, View v, int position, long id){
//Get selected items
Log.v("ListView l:", l.toString());
Log.v("View v:", v.toString());
Log.v("Position:", ""+position);
Log.v("ID: ", ""+id);
String selectedValue = (String) getListAdapter().getItem(position);
Bundle bundle = new Bundle();
bundle.putString("Name", selectedValue);
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
}
}
现在,随着 ArrayAdapter
等,发生的事情是我得到的项目清单。由于只有五个项目,并且由于我为它设置样式,大部分屏幕将变暗了(原活动
),只有列表中居中。问题是,我要完成的活动
应该有人在灰色区域单击列表框外。我不能为我的生活弄清楚如何。
Now, with the ArrayAdapter
et al, what happens is I get a list of items. As there are only five items, and due to the style I set for it, most of the screen is dimmed out (the original Activity
), and only the list is centred. The problem is, I want to finish the Activity
should someone click on the gray region outside of the list box. I cannot for the life of me figure out how.
我试图实施 OnTouchListener
,但的ListView
是不是让我这样做,我不能弄清楚如何称呼它为周围的的TextView
的的LinearLayout
容器。我是相当新到Android,所以请哑下来我。
I tried to implement an OnTouchListener
, but ListView
isn't letting me do so and I can't figure out how to call it for the LinearLayout
container that surrounds the TextView
. I'm fairly new to Android, so please dumb it down for me.
推荐答案
创建此XML布局并称之为list_layout.xml
Create this xml layout and call it "list_layout.xml":
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/my_background"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
然后,修改的onCreate()
为以下内容:
public void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.list_layout);
View background = findViewById(R.id.my_background);
background.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
RamdomList.this.finish();
}
});
setListAdapter(new RandomArrayAdapter(this, randomList));
}
我写了这关我的头顶,但不运行它,所以你可能会打一些事情了,但你的概念。
I wrote this off the top of my head without running it, so you might fight a few things off but you get the concept.
这篇关于透明/朦胧的ListView的背景 - 我要摧毁的ListView活动上点击后台时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!