0
我在main.xml中以下佈局:如何讓孩子的利潤率在Android中影響父母的視圖大小?
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:layout_width="125dp"
android:layout_height="300dp"
android:layout_gravity="center"
android:padding="5dp"
android:background="#FFFF00">
<View
android:id="@+id/placeholder"
android:layout_width="fill_parent"
android:layout_height="290dp"
android:background="#FF0000" />
</FrameLayout>
</FrameLayout>
而且在MainActivity.java下面的代碼:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View view = findViewById(R.id.placeholder);
MarginLayoutParams mlParams = (ViewGroup.MarginLayoutParams)view.getLayoutParams();
mlParams.topMargin = 50;
view.setLayoutParams(mlParams);
}
}
保證金將被應用到孩子的看法,但它根本不會影響父母的視圖大小。我可以「解決」這個問題與以下行:
((View)view.getParent()).getLayoutParams().height += 50;
但我怎麼能做到這一點沒有明確改變父母的`高度?這是可能的還是沒有多大意義?
不可以,固定大小是必要的。但由於沒有其他方式,我想這是正確的答案:)關於根視圖組,不要擔心。這只是一個例子。我只是用我在我面前的東西。 – 2012-03-16 19:16:37