平均划分屏幕宽度和一些布局问题

Mor*_*kel 3 android android-layout

我被困在某个地方......我正在编写一个用于记录放牧奶牛行为观察的应用程序.我的想法是,在屏幕的底部,我有一些字段可以识别各个动物.要注册观察,该字段将被拖动到顶部的一个字段,即将240拖到Grazing以显示现在是奶牛#240放牧.

我的观察记录器应用程序的屏幕截图

使用许多线性布局构建屏幕布局.基本上布局是

<LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical">
    <LinearLayout
       android:layout_width="fill_parent"
       android:layout_height="250dp"
       android:orientation="vertical">
       <LinearLayout
          android:layout_width="100dp"
          android:layout_height="150dp"
          android:background="@drawable/shape">
         <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:text="Grazing" />
         </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

然后,linearlayout/textview模式在顶部重复三次,底部使用类似的模式(编辑xml的显示部分)

目前我遇到了三个不同的问题:

1)如何在四个拖曳区域和下降区域之间平均分割顶部和底部的屏幕空间?我试图使用重量而不是宽度的固定值,但如果我尝试,应用程序崩溃. - 顺便说一下,区域的数量可能略有不同.

2)如何将文本置于区域中心.当我搜索时,我被告知我必须使用layout_gravity ="center",但这不起作用 - 据我理解布局,将textview放在线性布局的中心 - 我如何确保文本位于textview的中间?

3)为什么底部区域部分"掉下屏幕"?它们等于上部区域,表示它们被包裹在layout_gravity ="bottom"的线性布局中 - 我认为这会导致它们在屏幕底部有底部.

(如果重要的话,我正在手机上使用Aide进行开发)

Fah*_*him 6

以这种方式划分高度.在这里,我将屏幕的高度划分为3个linearlayouts

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal" >
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal" >
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal" >
        </LinearLayout>
    </LinearLayout>
Run Code Online (Sandbox Code Playgroud)