首页 > 解决方案 > 从外部布局动画视图到真实位置

问题描述

我有下一个 xml 结构:

<RelativeLayout
    ...>
    <RelativeLayout
        ...
        android:centerInParent=true/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="3"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="2"
            android:orientation="horizontal"
            android:layout_weight="1">
            <View
                android:id="@+id/top_left"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_weight="1"/>
            <View
                android:id="@+id/top_right"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_weight="1"/>
         </Linearlayout>

         <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="2"
            android:orientation="horizontal"
            android:layout_weight="1">
            <View
                android:id="@+id/middle_left"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_weight="1"/>
            <View
                android:id="@+id/middle_right"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_weight="1"/>
         </Linearlayout>

         <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="2"
            android:orientation="horizontal"
            android:layout_weight="1">
            <View
                android:id="@+id/bottom_left"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_weight="1"/>
            <View
                android:id="@+id/bottom_right"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_weight="1"/>
         </Linearlayout>

     </Linearlayout>

 </Relativelayout>

在此处输入图像描述

我需要像图片一样放置视图(如果视图有 4 个正方形,我需要放置在这些正方形的中间)

加载视图后,我需要将所有视图从父 RelativeLayout 中心设置为正常视图位置。

我尝试将 RelativeLayout 作为父级并为所有视图设置动画,但视图可以更改它们的大小,所以我不知道每个视图的最终位置。

反正有没有用上面写的结构来实现?

谢谢!

标签: androidanimationandroid-gridlayout

解决方案


我解决了这个问题,添加到所有视图的父母:

android:clipChildren="false"
android:clipToPadding="false"

推荐阅读