android - tab as like fileexploler -
how can put tab @ above..
i want type of tab when click item show on above,can give snippet or links.. , please tell brief if available how can this.. show in figure red rectangle there android tools or library.... or directly can code??
thanks in advance
rectangle describe want
belove image
..
i have made simple project you. should make more beautiful wasn't focusing on that, on code.
first add these values color.xml
<resources> <color name="buttongrey">#7a7a7a</color> <color name="layoutholderstartcolor">#f7f7f7</color> <color name="layoutholderendcolor">#e1e1e1</color> </resources>
next create background button holder , name gradient_button_holder.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startcolor="@color/layoutholderstartcolor" android:endcolor="@color/layoutholderendcolor" android:angle="270" /> <corners android:radius="3dp" /> </shape>
now create activity_main.xml
note: using images, download whole project @ bottom , them out
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <relativelayout android:id="@+id/pathholder" android:layout_width="match_parent" android:layout_height="35dp" android:layout_alignparenttop="true" android:background="@drawable/gradient_button_holder" android:gravity="center_vertical"> <button android:id="@+id/btnadd" android:layout_width="29dp" android:layout_height="29dp" android:layout_alignparentright="true" android:layout_marginbottom="3dp" android:layout_marginleft="3dp" android:layout_marginright="3dp" android:layout_margintop="3dp" android:background="@color/buttongrey" android:gravity="center" android:onclick="onbtnadd" android:text="+" android:textsize="15sp"/> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentdescription="@string/app_name" android:src="@drawable/seperator" android:visibility="gone"/> <horizontalscrollview android:id="@+id/btnscrollview" android:layout_width="wrap_content" android:layout_height="35dp" android:layout_alignparentleft="true" android:layout_toleftof="@id/btnadd"> <linearlayout android:id="@+id/btnfolderholder" android:layout_width="wrap_content" android:layout_height="35dp" android:orientation="horizontal"> </linearlayout> </horizontalscrollview> </relativelayout> </relativelayout>
next create utils class
import android.annotation.suppresslint; import android.os.build; import android.view.view; import java.util.concurrent.atomic.atomicinteger; public class utils { private static final atomicinteger snextgeneratedid = new atomicinteger(1); /** * generate value suitable use in setid(int}. * value not collide id values generated @ build time aapt r.id. * * @return generated id value */ private static int generateviewid() { (; ; ) { final int result = snextgeneratedid.get(); // aapt-generated ids have high byte nonzero; clamp range under that. int newvalue = result + 1; if (newvalue > 0x00ffffff) { newvalue = 1; // roll on 1, not 0. } if (snextgeneratedid.compareandset(result, newvalue)) { return result; } } } @suppresslint("newapi") public static int generateid() { if (build.version.sdk_int < build.version_codes.jelly_bean_mr1) { return generateviewid(); } else { return view.generateviewid(); } } }
and mainactivity
import android.graphics.color; import android.os.environment; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.util.typedvalue; import android.view.view; import android.view.viewgroup; import android.view.viewtreeobserver; import android.widget.button; import android.widget.horizontalscrollview; import android.widget.imageview; import android.widget.linearlayout; import android.widget.toast; import java.io.file; public class mainactivity extends actionbaractivity { private linearlayout btnholder; private horizontalscrollview scroller; //parent folders private viewtreeobserver observer; //needed scroll end private toast toast; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); init(); makebuttons(environment.getexternalstoragedirectory().getpath(), "folder1", "folder2", "folder3"); } private void makebuttons(string... values) { stringbuilder sb = new stringbuilder(values.length * 2); (int = 0; < values.length - 1; ++i) { sb.append(values[i]); sb.append(file.separator); addbutton(values[i], sb.tostring(), true); } sb.append(values[values.length - 1]); addbutton(values[values.length - 1], sb.tostring(), false); } private void init() { setwidgetconnections(); observer = scroller.getviewtreeobserver(); observer.addongloballayoutlistener(new viewtreeobserver.ongloballayoutlistener() { public void ongloballayout() { // scroll last folder (displayed on // right) scroller.fullscroll(horizontalscrollview.focus_right); } }); } private void setwidgetconnections() { btnholder = (linearlayout) findviewbyid(r.id.btnfolderholder); scroller = (horizontalscrollview) findviewbyid(r.id.btnscrollview); } public void onbtnadd(view v) { } private void addbutton(final string text, final string path, boolean withimage) { // dynamic call add buttons linearlayout.layoutparams params = new linearlayout.layoutparams(linearlayout.layoutparams.wrap_content, viewgroup.layoutparams.wrap_content); button btn = new button(this); btn.setid(utils.generateid()); btn.settext(text); btn.settextcolor(color.black); btn.settextsize(typedvalue.complex_unit_dip, 12); btn.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { gotopath(path); } }); //btn.setbackgroundresource(r.drawable.gradient_button_holder); btnholder.addview(btn, params); if (withimage) { imageview view = new imageview(this); view.setbackgroundresource(r.drawable.seperator2); btnholder.addview(view, params); } } private void gotopath(string path) { showtoast(path); } private void showtoast(string text) { if (toast != null) { toast.cancel(); } toast = toast.maketext(this, text, toast.length_short); toast.show(); } }
this final result , note horizontally scrollable
you can download whole project here
Comments
Post a Comment