Android 是否更改抽屉布局中的线性布局宽度?
如何在抽屉布局中更改LinearLayout的参数 我试过:Android 是否更改抽屉布局中的线性布局宽度?,android,xml,layout,Android,Xml,Layout,如何在抽屉布局中更改LinearLayout的参数 我试过: LinearLayout linearLayout; onCreate之后: drawerLinearLayout = (LinearLayout)findViewById(R.id.drawer); // drawer is the id of the linearlayout, where I want to change its params DrawerLayout.LayoutParams lp = new D
LinearLayout linearLayout;
onCreate之后:
drawerLinearLayout = (LinearLayout)findViewById(R.id.drawer);
// drawer is the id of the linearlayout, where I want to change its params
DrawerLayout.LayoutParams lp = new DrawerLayout.LayoutParams(100,100);
linearLayout.setLayoutParams(lp);
xml类似于:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Main" />
<LinearLayout
android:id="@+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
呃,你有两个变量,你似乎混淆了,
linearLayout
和drawerlinerayout
。该代码无法运行。我必须更改什么才能使其工作?thx提供了更多的代码,以便我们可以看到您实际在做什么
public class MainActivity extends FragmentActivity {
LinearLayout drawerLinearLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
drawerLinearLayout = (LinearLayout)findViewById(R.id.drawer);
int mode = getResources().getConfiguration().orientation;
if (mode == 1) {
DrawerLayout.LayoutParams lp = new DrawerLayout.LayoutParams(2,2);
drawerLinearLayout.setLayoutParams(lp);
}
}}