我有框架布局和其内部的四个按钮线性布局。当我在xml中编写伟大工程,但我想用java代码编写。LinearLayout设置重力
这适用
<FrameLayout ...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="bottom">
<ImageButton
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<ImageButton
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<ImageButton
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</FrameLayout>
BUT这不起作用
tbr = new LinearLayout(getBaseContext());
LinearLayout.LayoutParams pa = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
pa.gravity = Gravity.BOTTOM; ///??
tbr.setLayoutParams(pa);
的FrameLayout FL = findbyid ... f1.addView(TBR);
你说的 “不工作” 是什么意思?如果你的意思是没有显示子视图,那是因为你没有添加它们。 – Jong
我的意思是说不会停下来......留在屏幕的顶部 – rikkima
它没有任何包含的视图,所以你怎么知道?尝试在里面添加一些视图。 – Jong