2012-04-02 75 views
0

我是一个初学者编程的android。我正在搜索如何在当前窗口布局上创建透明子视图。如何在xml布局中添加一些视图的子视图

我创建了简单的布局,这是来源:

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

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Simple text" /> 

</LinearLayout> 

现在我想在按下导航按钮来创建一个视图。该视图我想添加在这个布局的顶部,透明约40%。它应该是这个样子:

enter image description here

此外,它应该很容易添加按钮,下拉框,否则,我可以轻松删除了这一观点。

也许有人这样做,我可以分享想法,这是怎么做到的?

谢谢。

+0

使用RelativeLayout在其他视图上显示一个视图.. – 2012-04-02 12:51:32

回答

0

查出来这个,做编程

view.getBackground().setAlpha(100); // to make background transparent 

可以使用PopupWindow上显示父视图的顶部,下面

View mainview ; 
PopupWindow popupwindow; 


public void onCreate(Bundle savedInstanceState){ 

LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    mainview = inflater.inflate(R.layout.main, null, false); 
    setContentView(mainview); 

    // load sub menu from xml layout in popupwindow 
     View submenu_popup = inflater.inflate(R.layout.submenu_popup, null, false); 

// make backgraound transparent of popup submenu 
     submenu_popup.getBackground().setAlpha(100); 

     popupwindow = new PopupWindow(submenu_popup ,300,300,false); 
     popupwindow.setOutsideTouchable(true); 
     popupwindow.setTouchable(true); 

} 


// call it on click of button or menu to show submenu 
public void onClickButton(){ 

    int x=0,y=0; 
// show popupwindow on x, y position in main view (parent view) by using this 
    popupwindow.showAtLocation(mainview , Gravity.NO_GRAVITY, x, y); 

} 
0

可能是你应该学习如何使用“机器人:主题为” property