【问题标题】:Android - how matching size of the linearlayoutAndroid - 如何匹配线性布局的大小
【发布时间】:2013-04-04 16:21:33
【问题描述】:

您好,我有一个可以调整大小的布局,但我想同步 3 个不同的线性布局

第一个linearlayout作为header,第二个linearlayout作为leftscrollbar,第三个linearlayout作为内容容器,所以布局会是这样的

   ____________________________
  |_____|____|HEADER___|____|__|
  |     |____|____|____|____|__|
  |_____|____|____|____|____|__|
  |     |    |    Content   |  |
  |_____|____|____|____|____|__|
  | left|____|____|____|____|__|
  |_____|    |    |    |    |  |
  |     |    |____|____|____|__|
  |_____|____|____|    |____|__|
  |     |____|____|    |____|__|
  |_____|____|____|____|____|__|

标题和左滚动条是可滚动的并与内容同步,所以当我滚动内容时,标题和滚动条也会滚动。但那是另一回事,我已经成功地创造了它。现在我想使用捏添加缩放功能,所以我创建了一个捏视图来检测捏和计算比例,这也完成了。但是现在我想使用我使用 layoutparams 从捏计算的比例来调整布局的大小,但是当我尝试缩放布局时,布局不再匹配。

如您所见,标题的大小和左子大小是静态的,但内容的子视图的大小是动态的,所以我要匹配的是内容单元格的宽度与标题单元格的宽度和高度左栏和内容的高度

这是我的 xml 文件

<niko.twodimensionalscroll.PinchView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pvZoomContainer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:id="@+id/llContainerMain"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/llHeaderContainer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <LinearLayout
                android:id="@+id/llLeftBarContainer"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >
            </LinearLayout>

            <RelativeLayout
                android:id="@+id/rlContainerScrollView"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:drawingCacheQuality="low" >

                <niko.twodimensionalscroll.TwoDScrollView
                    android:id="@+id/tdScrollView"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:drawingCacheQuality="low" >

                    <LinearLayout
                        android:id="@+id/llContainerSchedule"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:drawingCacheQuality="low"
                        android:orientation="horizontal" >
                    </LinearLayout>
                </niko.twodimensionalscroll.TwoDScrollView>
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>

</niko.twodimensionalscroll.PinchView>

我希望我的问题足够清楚,但如果您需要其他信息,请在评论中提问,我会解释更多

谢谢

【问题讨论】:

  • 好把这三个布局放在一个相对的Layout中,
  • 所以将我的父视图更改为相对布局?或将 3 布局更改为相对布局?为什么它会影响我的代码?
  • 将 3 的父母改为亲戚
  • 你能解释一下它会如何影响我的布局吗?也许在答案中?谢谢

标签: android layout android-linearlayout pinchzoom


【解决方案1】:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:orientation="vertical" 
    android:background="#444444">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Header" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:background="#666666"
    android:layout_weight="1" >

    <LinearLayout
        android:layout_width="50dp"
        android:layout_height="match_parent"
        android:orientation="vertical" 
        android:background="#440000">
         <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="LeftBar" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent" 
        android:layout_weight="1"
        android:background="#000099">

          <TextView
              android:id="@+id/textView1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentTop="true"
              android:layout_centerHorizontal="true"
              android:layout_marginTop="158dp"
              android:text="Content" />

    </RelativeLayout>

</LinearLayout>

试试这样的方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-24
    • 2013-07-23
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多