0

我的 android 应用程序中有一个页面,其中有一个滑出菜单和一些需要在主屏幕中显示的数据。滑出菜单具有所需的菜单选项。

主页是 ListView 格式。我想要这个 ListView 中的 TableLayout 格式布局。问题是当我将布局更改为 TableLayout 时,它与我的 java 活动文件混淆了。

我想在此页面的主屏幕上以表格格式显示从外部源提取的数据。

随附 XML 和 Java 活动文件。

提前致谢。

XML 代码

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent" 
android:layout_weight="1"
android:background="@drawable/galaxy">

<!-- Menu Panel -->
<RelativeLayout
       android:id="@+id/menuPanel"
       android:layout_height="match_parent"
       android:layout_width="wrap_content"
       android:gravity="right"
       android:background="@drawable/grey"
       android:orientation="vertical" >

        <TextView
            android:id="@+id/menu_title_1"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="0dp" 
            android:paddingLeft="15dp"             
            android:gravity="center_vertical"
            android:background="@drawable/grey"
            android:textStyle="bold"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"
            android:text="MAIN  MENU">     
        </TextView>

        <View
            android:id="@+id/menu_item_divider_1"
            android:layout_width="fill_parent"
            android:layout_height="0.5dp"
            android:layout_marginLeft="0dp"
            android:layout_marginRight="0dp"
            android:layout_below="@+id/menu_title_1"
            android:background="#000000"/>

        <Button
            android:id="@+id/readall"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:layout_marginLeft="0dp"             
            android:gravity="center_vertical"
            android:textColor="#000000"
            android:layout_below="@+id/menu_item_divider_1"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="All Parameters"/>     


          <Button
            android:id="@+id/param1"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:layout_marginLeft="15dp"             
            android:gravity="center_vertical"
            android:textColor="#000000"
            android:layout_below="@+id/readall"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="Parameter 1"/>    

             <Button
            android:id="@+id/param2"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:layout_marginLeft="15dp"             
            android:gravity="center_vertical"
            android:textColor="#000000"
            android:layout_below="@+id/param1"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="Parameter 2"/>    

             <Button
            android:id="@+id/param3"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:layout_marginLeft="15dp"             
            android:gravity="center_vertical"
            android:textColor="#000000"
            android:layout_below="@+id/param2"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="Parameter 3"/>    

             <Button
            android:id="@+id/dtc"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:layout_marginLeft="0dp"             
            android:gravity="center_vertical"
            android:textColor="#000000"
            android:layout_below="@+id/param3"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="D.T.C."/>    


             <Button
            android:id="@+id/logout"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:layout_marginLeft="0dp"             
            android:gravity="center_vertical"
            android:textColor="#000000"
            android:layout_below="@+id/dtc"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="Log Out"/>    

        </RelativeLayout>

   <!-- Sliding Panel -->     
    <LinearLayout
            android:id="@+id/slidingPanel"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="left"
            android:orientation="vertical"
            android:background="@drawable/grey" >

            <RelativeLayout
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/black" >

                <View
                    android:id="@+id/header_vertical_divider_1"
                    android:layout_width="2dp"
                    android:layout_height="fill_parent"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="15dp"
                    android:layout_toRightOf="@+id/menuViewButton"
                    android:background="@drawable/grey" />

                    <ImageView
                        android:id="@+id/menuViewButton"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="15dp"
                        android:clickable="true"
                        android:contentDescription="Main Menu"
                        android:textColor="#000000"
                        android:src="@drawable/icon"
                        android:visibility="visible" />


                    <TextView
                        android:id="@+id/textView1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="22dp"
                        android:layout_toRightOf="@+id/header_vertical_divider_1"
                        android:text="ECU Description"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:textColor="#ffffff" />

            </RelativeLayout>

            <View
                 android:id="@+id/dividerHeaderBottom"
                 android:layout_width="fill_parent"
                 android:layout_height="1dp"
                 android:background="#414141" ></View>
             <ListView
                android:id="@+id/list"
                android:layout_width="match_parent"
                android:layout_height="fill_parent"
                android:divider="#000000"
                android:dividerHeight="0.5dp"
                android:background="@drawable/galaxy"         >

            </ListView>


    </LinearLayout>

             <LinearLayout
                 android:id="@+id/footer"
                 style="@android:style/ButtonBar"
                 android:layout_width="fill_parent"
                 android:layout_height="50dp"
                 android:layout_alignParentBottom="true"
                 android:layout_gravity="bottom|center"
                 android:background="@drawable/black"
                 android:orientation="horizontal" >

           <EditText
                android:id="@+id/DefUid"
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_below="@+id/textView2"
                android:layout_weight="0.50"
                android:digits="0123456789."
                android:hint="IP Address"
                android:maxLength="15"
                android:maxWidth="350dip"
                android:singleLine="true"
                android:windowSoftInputMode="adjustNothing" >


            </EditText>

            <EditText
                android:id="@+id/DefUid"
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_below="@+id/textView2"
                android:layout_weight="0.20"
                android:maxWidth="80dip"
                android:hint="Port"
                android:digits="0123456789"
                android:maxLength="4"
                android:singleLine="true" >

            </EditText>


                     <Button
                        android:id="@+id/conn"
                        android:layout_width="0px"
                        android:layout_height="40dp"
                        android:layout_weight="0.15"
                        android:text="C"/>



                   <Button
                        android:id="@+id/disc"
                        android:layout_width="0px"
                        android:layout_height="40dp"
                        android:layout_weight="0.15"
                        android:text="D"/>

                </LinearLayout>
</FrameLayout>

Java 活动文件

public class LayerStack extends Activity 
{

//Declare
private LinearLayout slidingPanel;
private boolean isExpanded;
private DisplayMetrics metrics; 
private ListView listView;
private RelativeLayout headerPanel;
private RelativeLayout menuPanel;
private int panelWidth;
private ImageView menuViewButton;
private static final int HIDE_TOOLBARS = 0;
private static final int SHOW_TOOLBARS = 1;
private static final int TOGGLE_TOOLBARS = 2;
Handler handler;
LinearLayout toolbarTop, toolbarBottom;


FrameLayout.LayoutParams menuPanelParameters;
FrameLayout.LayoutParams slidingPanelParameters;
LinearLayout.LayoutParams headerPanelParameters ;
LinearLayout.LayoutParams listViewParameters;


//@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState)
{   
    super.onCreate(savedInstanceState);
    setContentView(R.layout.page7);
    //ImageView myImage = (ImageView) findViewById(R.id.menuPanel);
    //myImage.setAlpha(100);
    // Get references to the elements in the layout

    //Initialize
    metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    panelWidth = (int) ((metrics.widthPixels)*0.50);

    headerPanel = (RelativeLayout) findViewById(R.id.header);
    headerPanelParameters = (LinearLayout.LayoutParams) headerPanel.getLayoutParams();
    headerPanelParameters.width = metrics.widthPixels;
    headerPanel.setLayoutParams(headerPanelParameters);

    menuPanel = (RelativeLayout) findViewById(R.id.menuPanel);
    menuPanelParameters = (FrameLayout.LayoutParams) menuPanel.getLayoutParams();
    menuPanelParameters.width = panelWidth;
    menuPanel.setLayoutParams(menuPanelParameters);

    slidingPanel = (LinearLayout) findViewById(R.id.slidingPanel);
    slidingPanelParameters = (FrameLayout.LayoutParams) slidingPanel.getLayoutParams();
    slidingPanelParameters.width = metrics.widthPixels;
    slidingPanel.setLayoutParams(slidingPanelParameters);

    listView = (ListView) findViewById(R.id.list);
    listViewParameters = (LinearLayout.LayoutParams) listView.getLayoutParams();
    listViewParameters.width = metrics.widthPixels;
    listView.setLayoutParams(listViewParameters);


    //Slide the Panel   
    menuViewButton = (ImageView) findViewById(R.id.menuViewButton);
    menuViewButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if(!isExpanded)
            {
                isExpanded = true;                                              

                //Expand
                new ExpandAnimation(slidingPanel, panelWidth,
                Animation.RELATIVE_TO_SELF, 0.0f,
                Animation.RELATIVE_TO_SELF, 0.50f, 0, 0.0f, 0, 0.0f);   


                Button b2 = (Button) findViewById(R.id.readall);
                b2.setOnClickListener(new View.OnClickListener()
                {

                    @Override
                    public void onClick(View v) 
                    {
                        Intent i = new Intent(LayerStack.this,AppActivity8.class);
                        startActivity(i);
                        finish();

                    }
                });
               Button b1 = (Button) findViewById(R.id.logout);
                b1.setOnClickListener(new View.OnClickListener()
                {

                    @Override
                    public void onClick(View v) 
                    {
                        new AlertDialog.Builder(LayerStack.this)
                        .setTitle("Log Out Confirmation")
                        .setMessage("Are you sure you want to log out?")
                        .setNegativeButton("No", null)
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener()
                        {

                            @Override
                            public void onClick(DialogInterface arg0,int arg1)
                            {
                                Intent i = new Intent(LayerStack.this,AppActivity4.class);
                                startActivity(i);
                                finish();

                            }

                        }).create().show();

                    }
                });
            }
            else
            {
                isExpanded = false;
                //Collapse
                new CollapseAnimation(slidingPanel,panelWidth,
                TranslateAnimation.RELATIVE_TO_SELF, 0.50f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f, 0, 0.0f, 0, 0.0f);


            }

        }
    });

}       
}
4

1 回答 1

0

我改用 MultiColumn ListView。

于 2013-04-30T21:03:40.227 回答