Java 按钮布局\u alignParentRight在第一个循环上不起作用?
我动态添加viewflipper,并在每个视图上添加多个视图,其中一个视图是包含两个按钮的RelativeLayer,一个按钮位于层的左侧,另一个按钮位于层的右侧 它适用于所有循环,但不适用于第一个循环,在第一个循环中,两个按钮都位于左侧的另一个按钮之上。 任何有帮助意见的人都将不胜感激Java 按钮布局\u alignParentRight在第一个循环上不起作用?,java,android,button,Java,Android,Button,我动态添加viewflipper,并在每个视图上添加多个视图,其中一个视图是包含两个按钮的RelativeLayer,一个按钮位于层的左侧,另一个按钮位于层的右侧 它适用于所有循环,但不适用于第一个循环,在第一个循环中,两个按钮都位于左侧的另一个按钮之上。 任何有帮助意见的人都将不胜感激 LayoutInflater inflater = LayoutInflater.from(this); ViewGroup parent = (ViewGroup) findViewById(R.id.sli
LayoutInflater inflater = LayoutInflater.from(this);
ViewGroup parent = (ViewGroup) findViewById(R.id.slider_holder);
for (int i = 0; i < temp.length; i++) {
ViewGroup np = (ViewGroup) findViewById(R.id.nexpre);
LinearLayout l=(LinearLayout) inflater.inflate(R.layout.flipper_slides, parent, false);
RelativeLayout next_prev =(RelativeLayout) inflater.inflate(R.layout.next_prev, l, false);
for (int k = 0; k< temp1.length; k++) {
ViewGroup nested_parent = (ViewGroup) findViewById(R.id.nested_slider_holder);
LinearLayout nl=(LinearLayout) inflater.inflate(R.layout.nested_flipper_slides, nested_parent, false);
TextView temp_tv1 =(TextView) inflater.inflate(R.layout.nested_flipper_tv, nl, false);
temp_tv1.setText(temp[i]+" "+temp1[k]);
nl.addView(temp_tv1);
ff.addView(nl);
}
next_prev.addView(nested_prev);
next_prev.addView(nested_next);
l.addView(ff);
l.addView(next_prev);
f.addView(l);
}
LayoutInflater充气机=LayoutInflater.from(此);
ViewGroup parent=(ViewGroup)findViewById(R.id.slider\u holder);
对于(int i=0;i
这是下一个_prev.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nexpre"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_marginTop="-50dip" >
</RelativeLayout>
下面是嵌套的_prev.xml
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Prev" >
</Button>
这是嵌套的_next.xml
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Next" >
</Button>
问题在于,在第一个循环中,原本应该一直向右的按钮没有按下。对于第一个循环之后的所有其他循环,它都有效,但不适用于第一个循环 我在代码中添加了这一行:
if(i==0){
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
next_prev.getChildAt(1).setLayoutParams(params);
}
对于第一个循环,我使用布局参数以编程方式“对齐父对象右侧”
无论如何,如果有人能解释为什么第一个循环的行为与其他循环不同,我将不胜感激