Android addresses Viewpager and ScrollView and listview problems with sliding conflicts
Last Update:2015-08-08
Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size:18px">Let's think about it. the ListView implementation is an item that is added to a layout,</span></p></p><p><p><span style="font-size:18px">So linearlayout can add item to it like a ListView answer is yes<br></span></p></p><p><p><span style="font-size:18px">Let's start by simulating the LinearLayout class of the ListView</span></p></p><p><p><span style="font-size:18px"><br></span></p></p><p><span style="font-size:18px">public class Linearlayoutforlistview extends LinearLayout {<br><br>Private ListAdapter adapter;<br>Private Onclicklistener Onclicklistener = null;<br>Private Ontouchlistener Ontouchlistener = null;<br><br><br>/**<br>* Binding Layout<br>*/<br>public void Bindlinearlayout () {<br>int count = Adapter.getcount ();<br>for (int i = 0; i < count; i++) {<br>View v = adapter.getview (i, null, null);<br><br>V.setlayoutparams (new layoutparams (layoutparams.fill_parent, layoutparams.wrap_content));<br>V.setontouchlistener (this.ontouchlistener);<br>V.setonclicklistener (this.onclicklistener);<br>V.setid (i);<br>AddView (v, i);<br>}<br>LOG.V ("counttag", "" + count);<br>}<br><br>Public Linearlayoutforlistview (context Context) {<br>Super (context);<br>}<br><br>Public Linearlayoutforlistview (context context, attributeset attrs) {<br>Super (context, attrs);<br>TODO auto-generated Constructor stub<br>}<br><br>/**<br>* Get Adapter<br>*<br>* @return Adapter<br>*/<br>Public ListAdapter Getadpater () {<br>Return adapter;<br>}<br><br>/**<br>* Set Data<br>*<br>* @param adpater<br>*/<br>public void Setadapter (listadapter Adpater) {<br>This.adapter = adpater;<br>Bindlinearlayout ();<br>}<br><br>/**<br>* Get Click events<br>*<br>* @return<br>*/<br>Public Onclicklistener Getonclicklistner () {<br>Return onclicklistener;<br>}<br><br>/**<br>* Set Click events<br>*<br>* @param onclicklistener<br>*/<br>public void Setonclicklinstener (onclicklistener Onclicklistener) {<br>This.onclicklistener = onclicklistener;<br>}<br><br>Public Ontouchlistener Getontouchlistener () {<br>Return ontouchlistener;<br>}<br><br>public void Setontouchlistener (ontouchlistener Ontouchlistener) {<br>This.ontouchlistener = ontouchlistener;<br>}<br><br>}</span><strong><strong><span style="font-size:18px"><br></span></strong></strong></p><p><p><br></p></p><p><p><br></p></p><p><p><span style="font-size:18px">It's like a listview.</span></p></p><p><p><br></p></p><p><p><span style="font-size:18px">When using the</span></p></p><p><p><br></p></p><p><span style="font-size:18px"><com.groupbuy.view.linearlayoutforlistview<br>Android:id= "@+id/linlistview"<br>Android:layout_width= "fill_parent"<br>android:layout_height= "wrap_content"<br>android:scrollbars= "vertical"<br>android:orientation= "vertical"<br>android:paddingleft= "5dp"<br>android:paddingright= "5dp"<br>android:paddingtop= "3dp"<br>Android:paddingbottom= "30dp"<br>android:background= "#ffFFFF" ><br><br></com.groupbuy.view.LinearLayoutForListView><br></span></p><p><p><br></p></p><p><p><span style="font-size:18px">Adapter is the same as the usual LISTVIEW.<br></span></p></p><p><p><br></p></p><p><p><span style="font-size:18px">Set Adapter</span></p></p><p><p><span style="font-size:18px">Linearlayoutforlistview msetuplist = (linearlayoutforlistview) Findviewbyid (r.id.linlistview);<br>Msetuplist.setonclicklinstener (setuplistclickevent);<br>Msetuplist.setontouchlistener (setuplisttouchevent);<br>Msetuplist.setadapter (new Mainlistadpter (this));</span></p></p><p><p><br></p></p><p><p><span style="font-size:18px">Touch Event Handling</span><br></p></p><p><span style="font-size:18px">View.ontouchlistener setuplisttouchevent = new View.ontouchlistener () {<br><br>@Override<br>public boolean OnTouch (View v, motionevent Event) {<br>TODO auto-generated Method Stub<br>Return false;<br>}<br>};<br>Click event Handling<br>View.onclicklistener setuplistclickevent = new View.onclicklistener ()<br>{<br>@Override<br>public void OnClick (View V) {<br>TODO auto-generated Method Stub<br>int position = V.getid ();<br>Intent intent=new Intent (homeactivity.this,shopdetail.class);<br>StartActivity (intent);<br>}<br>};</span></p><p><p><br></p></p><p><p><br></p></p><p><p><span style="font-size:18px">ok, so you can avoid the Conflict.<br></span></p></p><p><span style="font-size:18px"><scrollview<br>Android:layout_width= "fill_parent"<br>android:layout_height= "wrap_content" ><br><linearlayout<br>Android:layout_width= "fill_parent"<br>android:layout_height= "wrap_content"<br>android:orientation= "vertical"<br>><br><relativelayout<br>Android:layout_width= "fill_parent"<br>android:layout_height= "200dp"<br>><br><br><android.support.v4.view.viewpager<br>Android:id= "@+id/viewpager"<br>Android:layout_width= "fill_parent"<br>android:layout_height= "match_parent"/><br><br><br><linearlayout<br>Android:id= "@+id/viewgroup"<br>Android:layout_width= "fill_parent"<br>android:layout_height= "10dip"<br>Android:layout_alignparentbottom= "true"<br>Android:layout_marginbottom= "5dip"<br>android:layout_marginright= "10dip"<br>android:gravity= "right"<br>android:orientation= "horizontal" ><br></LinearLayout><br></RelativeLayout><br><linearlayout<br>Android:layout_width= "match_parent"<br>android:layout_height= "wrap_content"<br>android:layout_margintop= "1dp"<br>Android:background= "@drawable/more_item_press"<br>><br><linearlayout<br><br>Android:layout_width= "match_parent"<br>android:layout_height= "wrap_content"<br><br>Android:background= "@drawable/account_tab_bg"<br>android:orientation= "horizontal" ><br><br><textview<br>Android:id= "@+id/my_checkin"<br>Android:layout_width= "match_parent"<br>android:layout_height= "match_parent"<br>android:layout_margin= "8dp"<br>android:layout_weight= "1"<br><br>android:gravity= "center"<br>android:padding= "10dp"<br>android:text= "car wash"<br>Android:textcolor= "#666666"<br>Android:textsize= "17sp"/><br><br><textview<br>Android:id= "@+id/my_comment"<br>Android:layout_width= "match_parent"<br>android:layout_height= "match_parent"<br>android:layout_margin= "8dp"<br>android:layout_weight= "1"<br><br>android:gravity= "center"<br>android:padding= "10dp"<br>android:text= "tyre repair"<br>Android:textcolor= "#666666"<br>Android:textsize= "17sp"/><br><br><textview<br>Android:id= "@+id/my_photo"<br>Android:layout_width= "match_parent"<br>android:layout_height= "match_parent"<br>android:layout_margin= "8dp"<br>android:layout_weight= "1"<br> <br>android:gravity= "center"<br>android:padding= "10dp"<br>android:text= "mobile tyre"<br>Android:textcolor= "#666666"<br>Android:textsize= "17sp"/><br></LinearLayout><br></LinearLayout><br><com.groupbuy.view.linearlayoutforlistview<br>Android:id= "@+id/linlistview"<br>Android:layout_width= "fill_parent"<br>android:layout_height= "wrap_content"<br>android:scrollbars= "vertical"<br>android:orientation= "vertical"<br>android:paddingleft= "5dp"<br>android:paddingright= "5dp"<br>android:paddingtop= "3dp"<br>Android:paddingbottom= "30dp"<br>android:background= "#ffFFFF" ><br><br></com.groupbuy.view.LinearLayoutForListView><br><br></LinearLayout><br></ScrollView><br><br></span></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>Android addresses Viewpager and ScrollView and listview problems with sliding conflicts</p></p></span>