0

这是我的xmls(基本上有两个视图:B相对[]内的线性[ A])

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/A"
android:layout_width= "wrap_content"
android:layout_height= "wrap_content" >

<LinearLayout
android:id="@+id/B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>

</<RelativeLayout>

我将宽度设置B为屏幕宽度的 10 倍,即w*10

RelativeLayout.LayoutParams para = new RelativeLayout.LayoutParams(w*10, h);
B.setLayoutParams(para);

当我制作动画B时,

ObjectAnimator animation2 = ObjectAnimator.ofFloat(B, "x", -w)

它表明 的宽度Bw不是w*10,好像作为A父视图的 正在限制其宽度。

我应该怎么做才能拥有B's 宽度w*10

4

1 回答 1

1

子视图必须完全在其父视图内布局。在任何一个方向上,你都不能比你的父母大。所以是的,父母会限制孩子的宽度。当然,由于您的父级设置为包装内容,它应该增长到围绕 B。您是否尝试过调用 requestLayout 使其自行调整大小?

于 2013-05-22T02:50:55.530 回答