在android中,水平滚动在表格布局中不起作用

在android中,水平滚动在表格布局中不起作用,android,android-layout,Android,Android Layout,我有一个表布局,其中有5列定义。但由于第二列中有大量文本,内容将从屏幕上消失。所以我试着放置一个水平滚动条。但是做不到。我有一个以HorizontalScrollView为父级的TableLayout。布局如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layo

我有一个表布局,其中有5列定义。但由于第二列中有大量文本,内容将从屏幕上消失。所以我试着放置一个水平滚动条。但是做不到。我有一个以HorizontalScrollView为父级的TableLayout。布局如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Balance_Inquiry" >

    <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"                           
                   android:layout_gravity="center_horizontal" >

                <HorizontalScrollView
                    android:id="@+id/horizontalView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="3dip"
                    android:scrollbars="horizontal|vertical" >

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent" >

                        <TableLayout
                            android:id="@+id/table_layout_balance_inquiry"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:layout_weight="1.0"
                            android:stretchColumns="0,1,2,3,4,5" >
                        </TableLayout>
                    </LinearLayout>
                </HorizontalScrollView>
            </LinearLayout>
</LinearLayout>
private void addHeader() {
        // TODO Auto-generated method stub
         TableRow tr_head = new TableRow(this);
         tr_head.setId(10);
         tr_head.setBackgroundColor(getResources().getColor(R.color.bg_login));
         tr_head.setLayoutParams(new LayoutParams(
                 LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));

         TextView labelSrNo = new TextView(this);
         labelSrNo.setId(20);
         labelSrNo.setText("SL NO.");
         labelSrNo.setTextColor(Color.WHITE);
         labelSrNo.setPadding(5, 5, 5, 5);
         tr_head.addView(labelSrNo);// add the column to the table row here

         TextView labelACCNO = new TextView(this);
         labelACCNO.setId(21);// define id that must be unique
         labelACCNO.setText("ACC NO."); // set the text for the header 
         labelACCNO.setTextColor(Color.WHITE); // set the color
         labelACCNO.setPadding(5, 5, 5, 5); // set the padding (if required)
         tr_head.addView(labelACCNO); // add the column to the table row here

         TextView labelACCTYPE = new TextView(this);
         labelACCTYPE.setId(20);
         labelACCTYPE.setText("ACC TYPE");
         labelACCTYPE.setTextColor(Color.WHITE);
         labelACCTYPE.setPadding(5, 5, 5, 5);
         tr_head.addView(labelACCTYPE);// add the column to the table row here

         TextView labelAVAILBLNCE = new TextView(this);
         labelAVAILBLNCE.setId(21);// define id that must be unique
         labelAVAILBLNCE.setText("AVAIL BALANCE"); // set the text for the header 
         labelAVAILBLNCE.setTextColor(Color.WHITE); // set the color
         labelAVAILBLNCE.setPadding(5, 5, 5, 5); // set the padding (if required)
         tr_head.addView(labelAVAILBLNCE); // add the column to the table row here

         TextView extraBalance = new TextView(this);
         extraBalance.setId(21);// define id that must be unique
         extraBalance.setText("AVAIL BALANCE"); // set the text for the header 
         extraBalance.setTextColor(Color.WHITE); // set the color
         extraBalance.setPadding(5, 5, 5, 5); // set the padding (if required)
         tr_head.addView(extraBalance); 

         table_layout_balance_inquiry.addView(tr_head, new TableLayout.LayoutParams(
                 LayoutParams.MATCH_PARENT,
                 LayoutParams.WRAP_CONTENT));
    }

但是水平滚动不起作用。如何启用水平滚动?任何建议都有很大帮助

为LinearLayout parent和HorizonalScrollView尝试设置android:layout\u width=“match\u parent”尝试以下代码:-

   <ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

<HorizontalScrollView
    android:id="@+id/hscrll1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal">

        <TableLayout
            android:id="@+id/table_main_detail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@layout/shape">

        </TableLayout>
    </LinearLayout>
</HorizontalScrollView>
</ScrollView>

这是目前为我工作