如何使用两个部分在我的情况定义布局 [英] How to define a layout with two parts in my case

查看:103
本文介绍了如何使用两个部分在我的情况定义布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想定义布局,看起来是这样的:

我的意思是要对屏幕上方的黄色区域,保持它始终显示在屏幕上,同时,绿色的区域是<滚动型>

我想定义两个单独的布局文件,例如 yellow_area.xml &安培; green_area.xml ,然后将它们包含在一个的main.xml

但如何保持黄色区域总是可见的放大器;有绿地面积滚动? (这是使黄色区域看起来是上面的绿色区域)


解决方案

  

我想定义两个单独的布局文件,例如yellow_area.xml&安培; green_area.xml,包括他们在一个main.xml中。


如果你想要重新使用一个或两个人,那么这样做或使用片段是一个好主意......任何你的情况最好。


  

但如何保持黄色区域总是可见的放大器;有绿地面积滚动? (这是使黄色区域看起来是上面的绿色区域)


您应该能够通过使用 RelativeLayout的并使用属性

 的android:layout_below =@ ID / topLayout

<包括> 标记为贵的greeen 布局假设 topLayout ID 你的黄布局

修改

我觉得我上面的回答没有工作,由于查看 S中包括布局内数。使用的LinearLayout 父布局,并使用 layout_weight 内每个孩子的布局(和的ListView 解决问题。类似

  XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=垂直
    机器人:layout_gravity =CENTER_HORIZONTAL
    机器人:重力=CENTER_HORIZONTAL
    >
    &所述;! - 包括一个title_layout - >
   <包括
        机器人:ID =@ + ID / upper_area
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =0dp
        布局=@布局/ title_layout
        25:机器人layout_weight = /> //这里增加重量    <! - 以下title_layout列表视图 - >
    < ListView控件
        机器人:ID =@ + ID / DATA_LIST
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =0dp
        75:机器人layout_weight = /> // 和这里
< / LinearLayout中>

使用 layout_weight 垂直取向高度必须设置为 0dp layout_width =0dp为水平方向)

I would like to define a layout which looks like this:

What I mean is to have the yellow area on top of screen, keep it always visible on screen, while, the green area is a <ScrollView>.

I am thinking to define two separate layout files, e.g. yellow_area.xml & green_area.xml, and includes them in one main.xml.

But how to keep yellow area always visible & have green area scrollable? (That's to make yellow area looks like it is above green area)

解决方案

I am thinking to define two separate layout files, e.g. yellow_area.xml & green_area.xml, and includes them in one main.xml.

If you are wanting to re-use one or both of them then doing this or using fragments is a fine idea...whichever works best in your case.

But how to keep yellow area always visible & have green area scrollable? (That's to make yellow area looks like it is above green area)

You should be able to accomplish this by using a RelativeLayout and using the property

android:layout_below="@id/topLayout"

in the <include> tag for your "greeen layout assuming that topLayout is the id of your "yellow" layout.

Edit

I think my above answer didn't work due to the number of Views inside of the included layout. Using a LinearLayout as the parent layout and using layout_weight inside of each child layout ( and ListView fixes the problem. Something like

    ?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:orientation="vertical"
    android:layout_gravity="center_horizontal"
    android:gravity="center_horizontal"
    >
    <!--included a title_layout-->
   <include
        android:id="@+id/upper_area"  
        android:layout_width="fill_parent"
        android:layout_height="0dp"   
        layout="@layout/title_layout"
        android:layout_weight=".25"/>    // add weight here 

    <!--Listview below title_layout-->
    <ListView
        android:id="@+id/data_list"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight=".75"  />      // and here


</LinearLayout> 

Using layout_weight with a vertical orientation the height must be set to 0dp (layout_width="0dp" for horizontal orientation)

这篇关于如何使用两个部分在我的情况定义布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆