FreeSizeDraggableLayout
JosefinaMcC
9年前
<h2>介绍:</h2> <p>一个可自定义子控件大小及位置、相等大小的子控件间可通过拖动交换位置的ViewGroup</p> <h2>运行效果:</h2> <p><img src="https://simg.open-open.com/show/ed6c4054bceb21ea73361a0be7f92697.gif"></p> <h2>使用说明:</h2> <p>Gradle</p> <pre> <code class="language-java">dependencies { compile 'com.miao:freesizedraggablelayout:0.0.1' }</code></pre> <p>Maven</p> <pre> <code class="language-java"><dependency> <groupId>com.miao</groupId> <artifactId>freesizedraggablelayout</artifactId> <version>0.0.1</version> <type>pom</type> </dependency></code></pre> <p>Use it in your own code:</p> <p>1. xml:</p> <pre> <code class="language-java"> <com.miao.freesizedraggablelayout.FreeSizeDraggableLayout android:id="@+id/fsd_layout" android:layout_width="match_parent" android:layout_height="match_parent" /></code></pre> <p><span style="background-color:rgb(255, 255, 255); color:rgb(51, 51, 51)">2.设置</span></p> <pre> <code class="language-java">FreeSizeDraggableLayout fsdLayout = (FreeSizeDraggableLayout) findViewById(R.id.fsd_layout); fsdLayout.setUnitWidthNum(4); fsdLayout.setUnitHeightNum(4);</code></pre> <p><span style="background-color:rgb(255, 255, 255); color:rgb(51, 51, 51)">3.创建一个 DetailView 列表:</span></p> <pre> <code class="language-java">List<DetailView> list = new ArrayList<>(); /* DetailView: public DetailView(Point p, int width, int height, View v) { setPoint(p); setWidhtNum(width); setHeightNum(height); setView(v); } */ list.add(new DetailView(new Point(0, 0), 2, 2, createButton(1))); list.add(new DetailView(new Point(2, 0), 2, 2, createButton(2))); list.add(new DetailView(new Point(0, 2), 2, 2, createButton(3))); list.add(new DetailView(new Point(2, 2), 2, 2, createButton(4))); /* private Button createButton(int i) { final Button btn = new Button(getApplicationContext()); btn.setText("Button - " + i); btn.setBackgroundColor(Color.BLACK); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), btn.getText(), Toast.LENGTH_SHORT).show(); } }); return btn; } */</code></pre> <p><span style="background-color:rgb(255, 255, 255); color:rgb(51, 51, 51)">4.set the list as ViewGroup's datasource把这个列表作为freeSizeDraggableLayout的数据源</span></p> <pre> <code class="language-java">freeSizeDraggableLayout.setList(list);</code></pre> <p> </p> <p>项目地址: <a href="/misc/goto?guid=4959670456078190843" rel="nofollow">https://github.com/alivebao/FreeSizeDraggableLayout</a></p>