Skip to content

Commit 1281344

Browse files
committed
Add syntax highlighting to README
1 parent 25a7bc0 commit 1281344

File tree

1 file changed

+54
-44
lines changed

1 file changed

+54
-44
lines changed

README.md

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ Usage
1818
-----
1919
Add it to your project using Gradle:
2020

21-
compile 'com.jmedeisis:draglinearlayout:1.0.1'
21+
```groovy
22+
compile 'com.jmedeisis:draglinearlayout:1.0.1'
23+
```
2224

2325
The `DragLinearLayout` can be used in place of any `LinearLayout`. However, by default, children
2426
will not be draggable. To set an existing `View` as draggable, use
@@ -27,60 +29,68 @@ will not be draggable. To set an existing `View` as draggable, use
2729

2830
XML layout file:
2931

30-
<com.jmedeisis.draglinearlayout.DragLinearLayout
31-
xmlns:android="http://schemas.android.com/apk/res/android"
32-
android:id="@+id/container"
32+
```xml
33+
<com.jmedeisis.draglinearlayout.DragLinearLayout
34+
xmlns:android="http://schemas.android.com/apk/res/android"
35+
android:id="@+id/container"
36+
android:layout_width="match_parent"
37+
android:layout_height="match_parent" >
38+
39+
<TextView
40+
android:layout_width="match_parent"
41+
android:layout_height="wrap_content"
42+
android:text="@string/text" />
43+
44+
<ImageView
45+
android:layout_width="match_parent"
46+
android:layout_height="120dp"
47+
android:scaleType="centerCrop"
48+
android:src="@drawable/image"/>
49+
50+
<Button
51+
android:id="@+id/button"
3352
android:layout_width="match_parent"
34-
android:layout_height="match_parent" >
35-
36-
<TextView
37-
android:layout_width="match_parent"
38-
android:layout_height="wrap_content"
39-
android:text="@string/text" />
40-
41-
<ImageView
42-
android:layout_width="match_parent"
43-
android:layout_height="120dp"
44-
android:scaleType="centerCrop"
45-
android:src="@drawable/image"/>
46-
47-
<Button
48-
android:id="@+id/button"
49-
android:layout_width="match_parent"
50-
android:layout_height="wrap_content"
51-
android:text="@string/button_text"/>
52-
53-
</com.jmedeisis.draglinearlayout.DragLinearLayout>
54-
53+
android:layout_height="wrap_content"
54+
android:text="@string/button_text"/>
55+
56+
</com.jmedeisis.draglinearlayout.DragLinearLayout>
57+
```
58+
5559
Enabling drag & swap for all child views:
5660

57-
DragLinearLayout dragLinearLayout = (DragLinearLayout) findViewById(R.id.container);
58-
for(int i = 0; i < dragLinearLayout.getChildCount(); i++){
59-
View child = dragLinearLayout.getChildAt(i);
60-
// the child will act as its own drag handle
61-
dragLinearLayout.setViewDraggable(child, child);
62-
}
61+
```java
62+
DragLinearLayout dragLinearLayout = (DragLinearLayout) findViewById(R.id.container);
63+
for(int i = 0; i < dragLinearLayout.getChildCount(); i++){
64+
View child = dragLinearLayout.getChildAt(i);
65+
// the child will act as its own drag handle
66+
dragLinearLayout.setViewDraggable(child, child);
67+
}
68+
```
6369

6470
Use `#addDragView(View, View)`,`#addDragView(View, View, int)` and `#removeDragView(View)` to
6571
manage draggable children dynamically:
6672

67-
final View view = View.inflate(context, R.layout.view_layout, null);
68-
dragLinearLayout.addDragView(view, view.findViewById(R.id.view_drag_handle));
69-
70-
// ..
71-
72-
dragLinearLayout.removeDragView(view);
73+
```java
74+
final View view = View.inflate(context, R.layout.view_layout, null);
75+
dragLinearLayout.addDragView(view, view.findViewById(R.id.view_drag_handle));
76+
77+
// ..
78+
79+
dragLinearLayout.removeDragView(view);
80+
```
7381

7482
Attach an `OnViewSwapListener` with `#setOnViewSwapListener(OnViewSwapListener)` to detect changes
7583
to the ordering of child `View`s:
7684

77-
dragLinearLayout.setOnViewSwapListener(new DragLinearLayout.OnViewSwapListener() {
78-
@Override
79-
public void onSwap(View firstView, int firstPosition,
80-
View secondView, int secondPosition) {
81-
// update data, etc..
82-
}
83-
});
85+
```java
86+
dragLinearLayout.setOnViewSwapListener(new DragLinearLayout.OnViewSwapListener() {
87+
@Override
88+
public void onSwap(View firstView, int firstPosition,
89+
View secondView, int secondPosition) {
90+
// update data, etc..
91+
}
92+
});
93+
```
8494

8595
When placing the `DragLinearLayout` inside a `ScrollView`, call `#setContainerScrollView(ScrollView)`
8696
to enable the user to scroll while dragging a child view.

0 commit comments

Comments
 (0)