【问题标题】:Android horizontal and vertical layout developmentAndroid横竖布局开发
【发布时间】:2014-03-13 09:16:23
【问题描述】:

这是一个愚蠢的问题,但我正处于一个应用程序的中间,我想在其中开发一个布局:

此布局可以垂直和水平滚动。我想在那个表格视图下进行滚动视图,但是如何使它也可以水平滚动。数据来自网络服务,所以我不知道会有多少数据。

所以请指导我。

【问题讨论】:

标签: android android-layout android-tablelayout android-scrollview android-scroll


【解决方案1】:

同时水平和垂直滚动是不好的用户体验。我建议你只有一个,我在你的例子中看到的是水平的。如果必须同时拥有这两者,您可以在创建单元格时创建一个 ListView 并进入您的适配器,以将 Horizo​​ntal ScrollView 作为一个父级,在其中广告为您的水平 ScrollView 膨胀视图子项。

【讨论】:

    【解决方案2】:

    使用两个滚动视图不是一个好主意。但如果需要,您可以做一件事:

    创建 XML 布局为:

    <ScrollView
        android:id="@+id/scrollview_vertical_table"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
    
            <HorizontalScrollView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                tools:ignore="UselessParent" >
    
                <TableLayout
                    android:id="@+id/tablelayout"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:stretchColumns="*" >
    
                </TableLayout>
            </HorizontalScrollView>
        </LinearLayout>
    </ScrollView>
    

    并以编程方式在此表中插入记录或行:

    TableLayout tableLayoutTransactionLineHeading = (TableLayout) findViewById(R.id.tablelayout);
    for(int j=0; j<rows; j++){      
        TableRow tableRow = new TableRow(this);
        tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
    
        TextView lineno = new TextView(this);
        lineno.setText(lineNo[j]);
        lineno.setPadding(10, 10, 10, 10);
        lineno.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
        tableRow.addView(lineno);
    
        View v = new View(this);
                v.setLayoutParams(new TableRow.LayoutParams(1, TableRow.LayoutParams.MATCH_PARENT));
                v.setBackgroundColor(Color.rgb(50, 50, 50));
                tableRow.addView(v);
    
        tableLayout.addView(tableRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT,0f));
    }
    

    希望这会对你有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-12
      相关资源
      最近更新 更多