Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.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 如何将framelayout元素的前图像视图发送到元素的末尾等_Android - Fatal编程技术网

Android 如何将framelayout元素的前图像视图发送到元素的末尾等

Android 如何将framelayout元素的前图像视图发送到元素的末尾等,android,Android,我已经创建了一个新的布局,它是FrameLayout类型,并且我已经添加了图像视图的四个元素,我希望以编程方式将第一个图像视图结束 简而言之,以编程方式重新排列framelayout的元素。假设我们这样做,听按钮clickListener <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/framelayout"

我已经创建了一个新的布局,它是FrameLayout类型,并且我已经添加了图像视图的四个元素,我希望以编程方式将第一个图像视图结束
简而言之,以编程方式重新排列framelayout的元素。假设我们这样做,听按钮clickListener

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/framelayout">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@mipmap/a20141008_091817"
        android:id="@+id/i1"/>
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@mipmap/a20141008_091819"
        android:id="@+id/i2"/>
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@mipmap/a20141008_091821"
        android:id="@+id/i3"/>
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@mipmap/a20141008_091823"
        android:id="@+id/i4"/>

    </FrameLayout>


非常感谢您的帮助。

如何将ImageView的可见性更改为“不可见/消失”,以便只显示要显示的视图?

在这种情况下,您似乎要重新排列
框架布局的子视图。我建议您只需使用
ViewGroup
,使用
getChildAt(一些索引)
,addView(viewToAdd,index来放置它)以及removeViewAt(一些索引)来实现重新排序;在我建议的解决方案中-我假设布局不会改变(这可以改进):


我希望这能帮助你和其他人。您还可以在和中签出所选答案,并显示如何重新排序视图。

首先。非常感谢每一位帮助我的人。 然后,我以良好的实践方式解决了我的问题,我希望与您分享,将来任何人都可能需要它。 台阶

  • 创建一个框架布局,如我问题中的xml所示
  • 将图像添加到frameLayout中
  • 创建一个java文件并将其连接到xml
  • 我们必须知道framlayout中所有图像的ID
  • 创建一个计时器,它将在X秒内更改图像的顺序
  • 将所有图像的计数输入framLayout
  • 创建Intager变量,该变量将确定下一个要带到前面的图像
  • 如我所述,仍在调用计时器以在x时间内工作
  • create方法停止计时器,如果需要的话。在我的例子中,我在onPause()方法中停止计时器

    这是执行上述所有步骤的java文件。希望它能帮助任何人

  • 公共类FrameLayout5扩展了AppCompatActivity{

    FrameLayout frameLayout; 
    Handler handler;             // this class will work as timer for change the order of images in delay 
    List<Integer> views;    //  this Array list will store all the ids of all the ImageViews into framelayout 
    int counter;        //  this counter will help us to find the next element to bring it to front 
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame_layout5);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    
        frameLayout = (FrameLayout) findViewById(R.id.framelayout);
        handler = new Handler();
        views = new ArrayList<Integer>();
        counter=0;
    
        // get all the children of framelayout 
        for (int i = 0; i < frameLayout.getChildCount() ; i++) {
            views.add(frameLayout.getChildAt(i).getId());
        }
    
        handler.postDelayed(runnable, 1000); // 1000 mean that this method will excute every 1 second 
    
    
    }
    
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
    
            int i=counter%(frameLayout.getChildCount());    
                counter++;
            ImageView a = (ImageView) findViewById(views.get(i));
    
            frameLayout.bringChildToFront(a);
    
            handler.postDelayed(runnable, 1000);
            Log.d("run", "called "+i);
        }
    };
    
    @Override
    protected void onStop() {
        super.onStop();
        handler.removeCallbacks(runnable);
    }
    
    FrameLayout;
    Handler;//此类将用作计时器,用于更改延迟中的图像顺序
    列表视图;//此数组列表将所有ImageView的所有ID存储到framelayout中
    int counter;//此计数器将帮助我们找到下一个元素,使其位于前面
    @凌驾
    创建时受保护的void(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity\u frame\u layout5);
    Toolbar Toolbar=(Toolbar)findViewById(R.id.Toolbar);
    设置支持操作栏(工具栏);
    frameLayout=(frameLayout)findviewbyd(R.id.frameLayout);
    handler=新的handler();
    视图=新的ArrayList();
    计数器=0;
    //获取framelayout的所有子级
    对于(int i=0;i
    }

    @昂贵的肚子
    @ishmaelMakitla

    我考虑过这一点,但我认为这不是一个好的做法,在框架布局中,我读到可以重新排列其观点。顺便说一下,谢谢你的回复。你可以看到我是如何解决我的问题的。非常感谢您的帮助。从前端到后端的交换在哪里?好的,我想代码示例将帮助您开始。让我添加您重新订购物品的那一块。一秒钟…更新了答案,请检查一下,让我知道这是否有效。首先非常感谢兄弟。您的方式可以工作,但很抱歉,这是我的问题,因为我正在寻找如何使用framelayout做同样的工作,我发现这种方式,它的工作很好framelayout.bringChildToFront(framelayout.getChildAt(1));我认识那个兄弟。谢谢你的关注,这只是一个建议。当然我会给你正确的答案等一下
    FrameLayout frameLayout; 
    Handler handler;             // this class will work as timer for change the order of images in delay 
    List<Integer> views;    //  this Array list will store all the ids of all the ImageViews into framelayout 
    int counter;        //  this counter will help us to find the next element to bring it to front 
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame_layout5);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    
        frameLayout = (FrameLayout) findViewById(R.id.framelayout);
        handler = new Handler();
        views = new ArrayList<Integer>();
        counter=0;
    
        // get all the children of framelayout 
        for (int i = 0; i < frameLayout.getChildCount() ; i++) {
            views.add(frameLayout.getChildAt(i).getId());
        }
    
        handler.postDelayed(runnable, 1000); // 1000 mean that this method will excute every 1 second 
    
    
    }
    
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
    
            int i=counter%(frameLayout.getChildCount());    
                counter++;
            ImageView a = (ImageView) findViewById(views.get(i));
    
            frameLayout.bringChildToFront(a);
    
            handler.postDelayed(runnable, 1000);
            Log.d("run", "called "+i);
        }
    };
    
    @Override
    protected void onStop() {
        super.onStop();
        handler.removeCallbacks(runnable);
    }