【问题标题】:Table Layout Auto Adjust the ImageView表格布局自动调整 ImageView
【发布时间】:2011-07-07 19:01:42
【问题描述】:

我正在使用表格布局来放置 ImageView,我正在连续添加 5 个 imageView,现在我希望根据屏幕宽度所有 ImageViews 自动调整它们之间的距离,我该怎么做,我的 TableLayout 如下所示。 .

    <TableLayout android:id="@+id/tableLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/transparent_background">
            <TableRow android:id="@+id/tableRow1" android:layout_height="wrap_content" android:stretchColumns="*" android:layout_width="fill_parent">
                <ImageView android:layout_height="wrap_content" android:id="@+id/imageView1" android:layout_width="wrap_content" android:src="@drawable/tea"></ImageView>
                <ImageView android:layout_height="wrap_content" android:id="@+id/imageView2" android:layout_width="wrap_content" android:src="@drawable/bye" ></ImageView>
                <ImageView android:layout_height="wrap_content" android:id="@+id/imageView3" android:layout_width="wrap_content" android:src="@drawable/brb" ></ImageView>
                <ImageView android:layout_height="wrap_content" android:id="@+id/imageView4" android:layout_width="wrap_content" android:src="@drawable/pizza" ></ImageView>
                <ImageView android:layout_height="wrap_content" android:id="@+id/imageView5" android:layout_width="wrap_content" android:src="@drawable/beer"></ImageView>          
            </TableRow>             
            <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content"></TableRow>
            <TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content"></TableRow>
            <TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_height="wrap_content"></TableRow>

        </TableLayout>

【问题讨论】:

    标签: android uiimageview


    【解决方案1】:

    您好,首先您必须根据您必须更改图像视图大小的分辨率来获取屏幕分辨率。使用此代码查找屏幕长度和高度

    Display display = getWindowManager().getDefaultDisplay(); 
    int width = display.getWidth();
    int height = display.getHeight();
    

    试试这个链接它会帮助你动态改变图像视图

    set extended ImageView width and height programatically - android

    【讨论】:

    • 您好,感谢您的指导,现在转而尝试使用 GridView,它会使用 imageView 自动填充布局中的剩余位置。 . .
    猜你喜欢
    • 2018-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 2014-04-29
    • 1970-01-01
    相关资源
    最近更新 更多