我想更改宽度在主Activity中的一个片段?是可能的,因为我没有找到一个 “的LayoutParams” 与更改默认:动态调整大小片段android
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
int widthFfragment=300;
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
widthTot = size.x;
heightTot = size.y;
findViewById(R.id.f1).getLayoutParams().width = widthTot-widthFfragment;
}}
这是片段代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/f1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#330000"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment 1"
android:textAppearance="?android:attr/textAppearanceLarge" />
片段1。 java
public class Fragment1 extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//---Inflate the layout for this fragment---
return inflater.inflate(R.layout.fragment1, container, false);
}
}
感谢
谢谢,我需要调整的主要活动,这可能吗? – bill23
我用LayoutParams解决它并设置适当的大小。非常感谢 – bill23