簡體   English   中英

Android的布局。 流體布局和固定布局

[英]Layout for Android. Fluid layout and a fixed layout

我要開發一個需要使用類似布局顯示數據的Android應用程序。 我需要屏幕的兩個部分:

  • 流體高度隨設備分辨率而變化的布局
  • 第二種布局,以固定大小顯示內容

這個怎么做? 我使用了relativelayout和linearlayout,但我還沒有找到解決方案。 你可以幫幫我嗎?

代表我的布局線框的圖像

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/fixedlayout"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:orientation="vertical"
        android:id="@+id/fluidlayout" >
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:orientation="vertical"
        android:id="@+id/fixedlayout" >
    </LinearLayout>

</RelativeLayout>

使用LinearLayout更有效的解決方案

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp" >
    </LinearLayout>

</LinearLayout>

對於一個LinearLayout設置頂部布局到android:layout_weight="1" (和高度為0dp )和底部layout_height到固定值或android:layout_height="wrap_content"

<?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:orientation="vertical" >

    <View
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#FF0000" />

    <View
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#00FF00" />

</LinearLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM