【问题标题】:How do I shift the <include> layout to the bottom of the view如何将 <include> 布局移动到视图的底部
【发布时间】:2022-02-05 13:53:23
【问题描述】:

我正在尝试将包含的视图推到布局的底部,但是我没有任何运气。目前它位于布局的顶部。相同的代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/altercolor2"
    android:clickable="true"
    android:orientation="vertical" >

    <include
        layout="@layout/layout_grid_details_header_view"
        android:visibility="gone" />

     <include layout="@layout/last_updated_time" />

    <RelativeLayout
        android:id="@+id/markets_column_names"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/black"
        android:paddingBottom="3dp" >

        <TextView
            android:id="@+id/markets_column_name1"
            android:layout_width="75dp"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/markets_column_name2"
            android:textSize="12sp"
            android:gravity="right" />

        <TextView
            android:id="@+id/markets_column_name2"
            android:layout_width="75dp"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/markets_column_name3"
            android:textSize="12sp"
            android:gravity="right" />

        <TextView
            android:id="@+id/markets_column_name3"
            android:layout_width="85dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:textSize="12sp"
            android:paddingRight="6dp"
            android:gravity="right" />
    </RelativeLayout>

    <com.handmark.pulltorefresh.library.PullToRefreshListView
        android:id="@+id/markets_grid_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />



       <include layout="@layout/loading_no_results" />

</LinearLayout>

我希望在列表底部切换的主要内容是:&lt;include layout="@layout/last_updated_time" /&gt; 所以,我试过我也试过设置paddingbottom和layout_below:相对布局id,并尝试设置layout_gravity=bottom和gravity=botttom,仍然没有运气。任何线索如何将它推到视图的底部,即使它仍然保持可见列表很长,但在视图的底部,就像在底部重叠列表视图。

谢谢!贾斯汀

【问题讨论】:

    标签: android


    【解决方案1】:

    layout_widthlayout_height 属性赋予'include tag',然后你可以赋予它的任何父标签属性

    【讨论】:

      【解决方案2】:

      由于根layout 是带有垂直orientationLinearLayout,因此它将按照您拥有它们的顺序进行绘制。只需将其作为 xml 中的最后一个 View 将其绘制在前一个 View 下方,然后您就可以使用边距、填充等任何东西来将其放在您想要的位置。

      更好的选择是将根 layout 更改为 RelativeLayout 并为有问题的 View 提供属性

           android:layout_alignParentBottom="true
      

      您可能需要调整其他Views 的某些属性才能得到您想要的,但是如果没有看到它应该是什么样子的图像就很难说。此外,android:layout_below="" 不能与它的父级 layout 一起工作,因为它是 LinearLayout...这只是 RelativeLayout 的一个属性。

      使用代码示例编辑

      <?xml version="1.0" encoding="utf-8"?>
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@color/altercolor2"
          android:clickable="true" >
      
          <include
              layout="@layout/layout_grid_details_header_view"
              android:visibility="gone" />
      
           <include layout="@layout/last_updated_time"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_alignParentBottom="true" />
      
          <RelativeLayout
              android:id="@+id/markets_column_names"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:background="@color/black"
              android:paddingBottom="3dp" >
      
              <TextView
                  android:id="@+id/markets_column_name1"
                  android:layout_width="75dp"
                  android:layout_height="wrap_content"
                  android:layout_toLeftOf="@+id/markets_column_name2"
                  android:textSize="12sp"
                  android:gravity="right" />
      
              <TextView
                  android:id="@+id/markets_column_name2"
                  android:layout_width="75dp"
                  android:layout_height="wrap_content"
                  android:layout_toLeftOf="@+id/markets_column_name3"
                  android:textSize="12sp"
                  android:gravity="right" />
      
              <TextView
                  android:id="@+id/markets_column_name3"
                  android:layout_width="85dp"
                  android:layout_height="wrap_content"
                  android:layout_alignParentRight="true"
                  android:textSize="12sp"
                  android:paddingRight="6dp"
                  android:gravity="right" />
          </RelativeLayout>
      
          <com.handmark.pulltorefresh.library.PullToRefreshListView
              android:id="@+id/markets_grid_list"
              android:layout_width="match_parent"
              android:layout_height="match_parent" />
      
      
      
             <include layout="@layout/loading_no_results" />
      
      </RelativeLayout >
      

      【讨论】:

      • 线性布局显示无效参数,还有其他方法吗?
      • 你不应该再拥有LinearLayout。它应该是RelativeLayout。我会更新更多代码
      • 将其设置为相对布局会弄乱顶部标题,这些标题会消失,并且 last_updated_time 也不起作用,不确定如何修改当前代码
      • 这就是为什么我说您可能必须修改其他 Views 的属性,因为我不知道它应该是什么样子。 RelativeLayout Docs 显示所有可用属性。在顶部使用android:layout_alignParentTop="true",然后在下方使用android:layout_below="@id/idOfViewAboveThis"
      • “它不起作用”是什么意思?它不显示,不正确显示等...
      【解决方案3】:

      尝试使用框架布局:将您当前的线性布局设置为第一个孩子(删除您想要移动到底部的包含视图)。将包含视图设为第二个视图并将其 layout_gravity 设置为底部。

      【讨论】:

      • 你能用编程方式解释一下吗?
      • 以下是我在上面试图强调的结构:&lt;FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;LinearLayout (as given by you above,Just remove the INCLUDED layout that you want to move to bottom&gt; &lt;/LinearLayout&gt; &lt;include layout="@layout/last_updated_time" android:layout_gravity="bottom"/&gt; &lt;/FrameLayout&gt; 我希望这会有所帮助。我省略了一些明显的东西,因为我的目的只是向您展示结构。抱歉,代码格式不正确。我正在想办法做到这一点。
      猜你喜欢
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-13
      • 1970-01-01
      相关资源
      最近更新 更多