Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 以编程方式反转RelativeLayout中的布局_Android_Android Relativelayout_Android Viewgroup - Fatal编程技术网

Android 以编程方式反转RelativeLayout中的布局

Android 以编程方式反转RelativeLayout中的布局,android,android-relativelayout,android-viewgroup,Android,Android Relativelayout,Android Viewgroup,我有一个relativeLayout和三个视图的内部relativeLayout。这两种观点是相互对立的 <RelativeLayout android:id="@+id/includelayoutgroup" android:layout_width="match_parent" android:layout_height="match_parent"> <View xmlns:android="http://schemas.andr

我有一个relativeLayout和三个视图的内部
relativeLayout
。这两种观点是相互对立的

    <RelativeLayout
    android:id="@+id/includelayoutgroup"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/transparentColorView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:clickable="true"
        android:visibility="visible" />


    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/keyboard_main_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:visibility="visible">

        <include
            layout="@layout/transfer_keyboard_fragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </RelativeLayout>


    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/finalRequestView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:clickable="true"
        android:visibility="visible">

        <include
            layout="@layout/fragment_transfer_new_version_container_child"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </RelativeLayout>
</RelativeLayout>

有可能改变我的观点吗?我的意思是,在我的代码中,最后一个布局是
finalRequestView
,在按钮单击中,我会在第一个位置找到我的最后一个视图,以及其他视图在我视图中的位置,
如何解决这个问题?

我尝试通过以下演示反向布局&它可以按照您的要求工作,请看一看

ReverseLayout.java

public class ReverseLayout extends AppCompatActivity {

    LinearLayout llRoot;
    Button btReverseLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.reverse_layout);

        llRoot = (LinearLayout) findViewById(R.id.llRoot);
        btReverseLayout = (Button) findViewById(R.id.btReverseLayout);

        btReverseLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ArrayList<View> alViews = new ArrayList<View>();
                for (int i = llRoot.getChildCount() - 1; i >= 0; i--) {
                    View view = llRoot.getChildAt(i);
                    llRoot.removeViewAt(i);
                    alViews.add(view);
                }

                for (int j = 0; j < alViews.size(); j++) {
                    llRoot.addView(alViews.get(j));
                }
            }
        });
    }
}
公共类ReverseLayout扩展了AppCompatActivity{
根的线性布局;
按钮btReverseLayout;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(右布局、反向布局);
llRoot=(LinearLayout)findViewById(R.id.llRoot);
btReverseLayout=(按钮)findViewById(R.id.btReverseLayout);
btReverseLayout.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
ArrayList alViews=新的ArrayList();
对于(int i=llRoot.getChildCount()-1;i>=0;i--){
View=llRoot.getChildAt(i);
llRoot.removeViewAt(i);
添加(视图);
}
对于(int j=0;j
reverse_layout.xml布局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_6"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.tosc185.testproject.Activity6">

    <LinearLayout
        android:id="@+id/llRoot"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FF0000"
            android:gravity="center"
            android:orientation="vertical"
            android:padding="15dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1"
                android:textSize="16dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#00FF00"
            android:gravity="center"
            android:orientation="vertical"
            android:padding="15dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2"
                android:textSize="16dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#0000FF"
            android:gravity="center"
            android:orientation="vertical"
            android:padding="15dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="3"
                android:textSize="16dp" />
        </LinearLayout>

    </LinearLayout>

    <Button
        android:id="@+id/btReverseLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Reverse Layout" />
</RelativeLayout>

谢谢您的关注。您使用的是线性布局,方向是垂直的。您的代码是否可以与RelativeLayout一起使用?每个人的视野都在哪里?