hafez1
سه شنبه 31 فروردین 1395, 06:13 صبح
سلام دوستان .
من یه برنامه دارم و نیاز دارم که تعدادی تب داشته باشم که بتونم اگر دستم رو روی صفحه میکشم تبها رو عوض کنم و تب ها رو از راست به چپ نشون بده.
الان یه کدی دارم که اینجا میذارم ولی این دوتا ویژگی رو نداره.
میشه راهنمایییم کنید؟
این کدهای مربوط به فایل xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TabHost
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_x="0dp"
android:layout_y="0dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView1"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="Appinapps.com"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView2"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="Google.com"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView3"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="Android.com"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView4"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="Android.com"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView5"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="Android.com"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView6"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="Android.com"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
اینم کدهای مربوط به فایل جاوا
package smartlab.ir.monire.tab;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
public class MainActivity extends Activity {
TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//معرفی تب هاست
tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
//ایجاد تب شماره یک
TabHost.TabSpec spec1=tabHost.newTabSpec("TAB 1");
//دریافت لایه تب
spec1.setContent(R.id.tab1);
//نام تب
spec1.setIndicator("اندروید");
//ایجاد تب شماره دو
TabHost.TabSpec spec2=tabHost.newTabSpec("TAB 2");
spec2.setIndicator("سی++");
spec2.setContent(R.id.tab2);
//ایجاد تب شماره سه
TabHost.TabSpec spec3=tabHost.newTabSpec("TAB 3");
spec3.setContent(R.id.tab3);
spec3.setIndicator("سی");
TabHost.TabSpec spec4=tabHost.newTabSpec("TAB 4");
spec4.setContent(R.id.tab4);
spec4.setIndicator("جاوا");
TabHost.TabSpec spec5=tabHost.newTabSpec("TAB 5");
spec5.setContent(R.id.tab5);
spec5.setIndicator("اچ تی ام ال");
//افزودن تب ها به تب هاست جهت نمایش
tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
tabHost.addTab(spec4);
tabHost.addTab(spec5);
}
}
من یه برنامه دارم و نیاز دارم که تعدادی تب داشته باشم که بتونم اگر دستم رو روی صفحه میکشم تبها رو عوض کنم و تب ها رو از راست به چپ نشون بده.
الان یه کدی دارم که اینجا میذارم ولی این دوتا ویژگی رو نداره.
میشه راهنمایییم کنید؟
این کدهای مربوط به فایل xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TabHost
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_x="0dp"
android:layout_y="0dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView1"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="Appinapps.com"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView2"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="Google.com"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView3"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="Android.com"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView4"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="Android.com"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView5"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="Android.com"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView6"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="Android.com"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
اینم کدهای مربوط به فایل جاوا
package smartlab.ir.monire.tab;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
public class MainActivity extends Activity {
TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//معرفی تب هاست
tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
//ایجاد تب شماره یک
TabHost.TabSpec spec1=tabHost.newTabSpec("TAB 1");
//دریافت لایه تب
spec1.setContent(R.id.tab1);
//نام تب
spec1.setIndicator("اندروید");
//ایجاد تب شماره دو
TabHost.TabSpec spec2=tabHost.newTabSpec("TAB 2");
spec2.setIndicator("سی++");
spec2.setContent(R.id.tab2);
//ایجاد تب شماره سه
TabHost.TabSpec spec3=tabHost.newTabSpec("TAB 3");
spec3.setContent(R.id.tab3);
spec3.setIndicator("سی");
TabHost.TabSpec spec4=tabHost.newTabSpec("TAB 4");
spec4.setContent(R.id.tab4);
spec4.setIndicator("جاوا");
TabHost.TabSpec spec5=tabHost.newTabSpec("TAB 5");
spec5.setContent(R.id.tab5);
spec5.setIndicator("اچ تی ام ال");
//افزودن تب ها به تب هاست جهت نمایش
tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
tabHost.addTab(spec4);
tabHost.addTab(spec5);
}
}