1
我有一个静态布局,我在编程动态中设置了边距。保证金工作正常,但只是在肖像视图。这是XML布局
布局setMargins不能在横向模式下工作
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center_vertical" >
<RelativeLayout
android:id="@+id/rl_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/menubackground"
android:layout_weight="1.0"
android:gravity="center" >
<Button
android:id="@+id/btn_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/icon1"
android:gravity="center"
android:background="@null"
android:onClick="ActiveMenu"
android:text="@string/home"
android:textColor="@color/White"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_browse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:background="@drawable/menubackground"
android:gravity="center" >
<Button
android:id="@+id/btn_browse"
android:background="@null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/icon2"
android:gravity="center"
android:onClick="ActiveMenu"
android:text="@string/browse"
android:textColor="@color/White"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:background="@drawable/menubackground"
android:gravity="center" >
<Button
android:background="@null"
android:id="@+id/btn_account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/icon3"
android:gravity="center"
android:onClick="ActiveMenu"
android:text="@string/account"
android:textColor="@color/White"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_mybag"
android:background="@drawable/menubackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center" >
<Button
android:background="@null"
android:id="@+id/btn_mybag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/icon4"
android:gravity="center"
android:onClick="ActiveMenu"
android:text="@string/my_bag"
android:textColor="@color/White"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_no_Of_items"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/btn_mybag"
android:layout_marginRight="0.0dip"
android:background="@drawable/red_circle"
android:gravity="center"
android:text="1"
android:textColor="@color/White"
android:textSize="15.0dip"
android:textStyle="bold"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:background="@drawable/menubackground"
android:gravity="center" >
<Button
android:background="@null"
android:id="@+id/btn_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/icon5"
android:gravity="center"
android:onClick="ActiveMenu"
android:text="@string/more"
android:textColor="@color/White"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
我写了下面的保证金
Button btn_home, btn_browse, btn_account, btn_mybag, btn_more;
RelativeLayout rl_home, rl_browse, rl_account, rl_mybag, rl_more;
LinearLayout LinearLayout1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.browse);
btn_home=(Button) findViewById(R.id.btn_home);
btn_browse=(Button) findViewById(R.id.btn_browse);
btn_account=(Button) findViewById(R.id.btn_account);
btn_mybag=(Button) findViewById(R.id.btn_mybag);
btn_more=(Button) findViewById(R.id.btn_more);
rl_home=(RelativeLayout) findViewById(R.id.rl_home);
rl_browse=(RelativeLayout) findViewById(R.id.rl_browse);
rl_account=(RelativeLayout) findViewById(R.id.rl_account);
rl_mybag=(RelativeLayout) findViewById(R.id.rl_mybag);
rl_more=(RelativeLayout) findViewById(R.id.rl_more);
LinearLayout1=(LinearLayout) findViewById(R.id.LinearLayout1);
}
public void ActiveMenu(View v) {
if (R.id.btn_home == v.getId()) {
rl_home.setBackgroundResource(R.drawable.current_menu);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 0, 0);
rl_home.setLayoutParams(params);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
params1.setMargins(0, 15, 0, 0);
rl_browse.setBackgroundResource(R.drawable.menubackground);
rl_browse.setLayoutParams(params1);
rl_account.setBackgroundResource(R.drawable.menubackground);
rl_account.setLayoutParams(params1);
rl_mybag.setBackgroundResource(R.drawable.menubackground);
rl_mybag.setLayoutParams(params1);
rl_more.setBackgroundResource(R.drawable.menubackground);
rl_more.setLayoutParams(params1);
}
if (R.id.btn_browse== v.getId()) {
rl_browse.setBackgroundResource(R.drawable.current_menu);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 0, 0);
rl_browse.setLayoutParams(params);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
params1.setMargins(0, 15, 0, 0);
rl_home.setBackgroundResource(R.drawable.menubackground);
rl_home.setLayoutParams(params1);
rl_account.setBackgroundResource(R.drawable.menubackground);
rl_account.setLayoutParams(params1);
rl_mybag.setBackgroundResource(R.drawable.menubackground);
rl_mybag.setLayoutParams(params1);
rl_more.setBackgroundResource(R.drawable.menubackground);
rl_more.setLayoutParams(params1);
}
if (R.id.btn_account == v.getId()) {
rl_account.setBackgroundResource(R.drawable.current_menu);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 0, 0);
rl_account.setLayoutParams(params);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
params1.setMargins(0, 15, 0, 0);
rl_browse.setBackgroundResource(R.drawable.menubackground);
rl_browse.setLayoutParams(params1);
rl_home.setBackgroundResource(R.drawable.menubackground);
rl_home.setLayoutParams(params1);
rl_mybag.setBackgroundResource(R.drawable.menubackground);
rl_mybag.setLayoutParams(params1);
rl_more.setBackgroundResource(R.drawable.menubackground);
rl_more.setLayoutParams(params1);
}
if (R.id.btn_mybag == v.getId()) {
rl_mybag.setBackgroundResource(R.drawable.current_menu);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 0, 0);
rl_mybag.setLayoutParams(params);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
params1.setMargins(0, 15, 0, 0);
rl_browse.setBackgroundResource(R.drawable.menubackground);
rl_browse.setLayoutParams(params1);
rl_account.setBackgroundResource(R.drawable.menubackground);
rl_account.setLayoutParams(params1);
rl_home.setBackgroundResource(R.drawable.menubackground);
rl_home.setLayoutParams(params1);
rl_more.setBackgroundResource(R.drawable.menubackground);
rl_more.setLayoutParams(params1);
}
if (R.id.btn_more== v.getId()) {
rl_more.setBackgroundResource(R.drawable.current_menu);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 0, 0);
rl_more.setLayoutParams(params);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
params1.setMargins(0, 15, 0, 0);
rl_browse.setBackgroundResource(R.drawable.menubackground);
rl_browse.setLayoutParams(params1);
rl_account.setBackgroundResource(R.drawable.menubackground);
rl_account.setLayoutParams(params1);
rl_home.setBackgroundResource(R.drawable.menubackground);
rl_home.setLayoutParams(params1);
rl_mybag.setBackgroundResource(R.drawable.menubackground);
rl_mybag.setLayoutParams(params1);
}
}
代码是我犯什么错误? Portrate视图
景观视野
在横向视图改变当前项目后
在横向模式下缘工作正常,但它不适合于screen..when布局负荷拳头时间比它适合屏幕,但发射click事件之后就不能继续担任适合屏幕.. – 2013-05-06 11:20:34
问题出现在第三张图片中......点击任何项目后。 – 2013-05-06 12:32:57