【问题标题】:Android add TableLayout and LinearLayout together?Android一起添加TableLayout和LinearLayout?
【发布时间】:2015-12-23 12:25:21
【问题描述】:

我有一个基本的 LinearLayout,里面有一个 TableLayout 和 ImageView,我想把表格放在顶部,然后把图片放在底部中心,我该如何解决这个问题? 周四,我将所有行添加到 TableLayout 中的 java 代码,所以希望在代码中看到。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent"
app:showAsAction="ifRoom">

<TableLayout
    android:id="@+id/Table"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="1"
    android:shrinkColumns="0">
</TableLayout>

<!--<LinearLayout-->
    <!--android:layout_gravity="bottom"-->
    <!--android:id="@+id/secLayout"-->
    <!--android:orientation="vertical"-->
    <!--android:layout_width="wrap_content"-->
    <!--android:layout_height="wrap_content">-->

    <ImageView
        android:id="@+id/pic1"
        android:src="@mipmap/pic1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ImageView>

<!--</LinearLayout>-->

有什么想法吗?

【问题讨论】:

    标签: android layout imageview tablelayout


    【解决方案1】:

    请检查我的解决方案

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        app:showAsAction="ifRoom"  // remove it
        >
        <TableLayout
            android:id="@+id/Table"
            android:layout_width="match_parent"
            android:layout_height="0dp" // change it
            android:layout_weight = 1 // add it
            android:stretchColumns="1"
            android:shrinkColumns="0">
        </TableLayout>
    
        <ImageView
            android:id="@+id/pic1"
            android:src="@mipmap/pic1"
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </ImageView>
    
    </LinearLayout>
    

    希望有帮助

    【讨论】:

    • OK 会在 3 分钟内完成。
    • @Mikael, Syed Nazar Muhammad 谢谢你们俩 :)
    【解决方案2】:

    尝试使用RelativeLayout 而不是LinearLayout 作为父布局。

    使用android:layout_alignParentBottom="true" 对齐底部的ImageViewandroid:layout_centerHorizontal="true"ImageView 居中对齐。

    试试这个代码。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    app:showAsAction="ifRoom">
    
        <TableLayout
            android:id="@+id/Table"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/pic1"
            android:stretchColumns="1"
            android:shrinkColumns="0">
        </TableLayout>
    
        <ImageView
            android:id="@+id/pic1"
            android:src="@mipmap/pic1"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </ImageView>
    
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-07
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多