我正在尝试制作一个将出现在列表视图上的弹出窗口,具有透明背景,因此您仍然可以看到它后面的列表视图。
这是弹出窗口的xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00000000"
android:gravity="center_horizontal|center_vertical" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:background="@drawable/popup_bg"
android:padding="20dip" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<!-- Left column -->
<TextView
android:id="@+id/foodName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:ellipsize="marquee"
android:singleLine="true"
android:textSize="12sp" />
<TextView
android:id="@+id/calories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/foodName"
android:ellipsize="marquee"
android:singleLine="true"
android:textSize="12sp" />
<TextView
android:id="@+id/fat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/calories"
android:ellipsize="marquee"
android:singleLine="true"
android:textSize="12sp" />
<TextView
android:id="@+id/protein"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/fat"
android:ellipsize="marquee"
android:singleLine="true"
android:textSize="12sp" />
<TextView
android:id="@+id/carbohydrates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/protein"
android:ellipsize="marquee"
android:singleLine="true"
android:textSize="12sp" />
<!-- Bottom -->
<TextView
android:id="@+id/sodium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/carbohydrates"
android:ellipsize="marquee"
android:singleLine="true"
android:textSize="12sp" />
<Button
android:id="@+id/btnAddFood"
android:layout_width="200dip"
android:layout_height="50dip"
android:layout_alignParentLeft="true"
android:layout_below="@+id/sodium"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:background="@drawable/popup_buttons"
android:singleLine="true"
android:text="Add this food" />
</RelativeLayout>
</FrameLayout>
</RelativeLayout>
这是调用它的活动(删除了一些不必要的行):
public class FoodPopupActivity extends Activity{
String foodName;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
try{
// receive food
Bundle extras = getIntent().getExtras();
final Food food = (Food) extras.get("food");
String foodName = food.getName();
// set view
setContentView(R.layout.activity_food_popup);
View background = findViewById(R.id.background);
// background.setBackgroundColor(00000000);
background.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View arg0, MotionEvent arg1){
finish();
return false;
}
});
addFood.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// pass an intent with user location and where they need to go
// then start the intent
MainActivity.myMeal.addFood(food);
Toast.makeText(getApplicationContext(),food.getName()+" added to your menu for today.", Toast.LENGTH_SHORT).show();
finish();
}
});
}catch(Exception e){
Toast.makeText(getApplicationContext(), "Error displaying food data, Try again, "+e.toString(), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(),foodName+" "+String.valueOf(foodCalories), Toast.LENGTH_SHORT).show();
}
}
}
我相信我已经尝试在相对布局、线性布局和列表视图上加载它,但到目前为止没有成功。我究竟做错了什么?