0

我正在尝试创建一个布局,在按钮单击上将显示一个列表视图(弹出)并完成但主要问题是列表视图使网格视图向下滑动,我不希望那样。我希望列表视图在网格视图上弹出. 帮助怎么做我的代码是

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"  
android:tag="medium"  
android:id="@+id/test"
android:background="@drawable/background_new" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:layout_marginBottom="10dip"
        android:background="@drawable/topbar_new"
        android:gravity="center"
        android:orientation="vertical" >

         <TextView
            android:id="@+id/tv_apps_Heading"
            style="@style/Heading"
             android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:text="My Apps"
            /> 

         <Button
    android:id="@+id/menuBtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
     android:background="@drawable/home"
   /> 
    </RelativeLayout>

      <RelativeLayout
         android:id="@+id/listview"
         android:layout_width="80dp"
         android:layout_height="50dp"
         android:gravity="right"
         android:orientation="horizontal"
       >
         <ListView 
    android:layout_height="80dp" 
    android:id="@+id/ListView_Menu" 
    android:layout_width="80dp"        
    android:layout_gravity="right"   
    android:layout_below="@+id/menuBtn"    
    android:listSelector="@android:color/transparent"
  />                  
                  </RelativeLayout>




    <GridView
        android:id="@+id/MyGrid"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dip"
        android:columnWidth="90dp"
        android:gravity="center"
        android:horizontalSpacing="10dp"
        android:numColumns="auto_fit"
        android:scrollbars="none"
        android:stretchMode="columnWidth"
        android:verticalSpacing="10dp" >
    </GridView>
</LinearLayout>
</RelativeLayout>

爪哇代码

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.home);

     menuList = (ListView) findViewById(R.id.ListView_Menu);

     menuBtn = (Button) findViewById(R.id.menuBtn);
    menuBtn.setOnClickListener(this);       

        menuList.setOnItemClickListener(new     AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) {

                // Note: if the list was built "by hand" the id could be used.
                // As-is, though, each item has the same id

                TextView textView = (TextView) itemClicked;
                String strText = textView.getText().toString();

                if (strText.equalsIgnoreCase("First Section")) {
                    // Launch the Game Activity
                    startActivity(new Intent(Activity.this,
        Activity.class));

                } else if (strText.equalsIgnoreCase("Second Section")) {
                    // Launch the Help Activity
                    startActivity(new Intent(Activity.this,
        NameActivity.class));

               } 

                else if (strText.equalsIgnoreCase("Fourth Section")) {
                    // Launch the Settings Activity
                    startActivity(new Intent(Activity.this,
        Profile.class));

                   // menuList.setVisibility(View.INVISIBLE);
                }else if (strText.equalsIgnoreCase("Logout")) {
                    // Launch the Scores Activity
                    LoginscreenCall();

                }
            }
        });

  @SuppressLint("NewApi")
@Override
public void onClick(View v) {
// TODO Auto-generated method stub  
    globalMenu=(RelativeLayout)findViewById(R.id.listview);
    globalMenu.setVisibility(View.VISIBLE);

    String[] option={"First Section", "Second Section", "THird Section", 
            "Fourth Section", "Log Out"};

    ArrayAdapter<String> adapt= new ArrayAdapter<String>(this,
            R.layout.menu_item, option);
    menuList.setAdapter(adapt);

    if(menuList.getVisibility()==View.VISIBLE)
    {
        menuList.setVisibility(View.GONE);
        Log.e("Menu Button", "Invisible");

    }
    else{
        menuList.setAdapter(adapt);
         menuList.setVisibility(View.VISIBLE);
         Log.e("Menu Button", "Visible");
    }


}
4

1 回答 1

0

感谢所有试图提供帮助的人。我用谷歌搜索,发现我可以使用快速操作来达到我的目的,我用作参考的链接是

londatigalorensiuswlt

谢谢你那里得到了这些答案。

完成此操作后,我将发布我使用过的代码。

于 2013-05-30T05:00:11.360 回答