[英]Android scrollable view inside a tab layout
我目前在android版式上的標簽內使用可滾動視圖時遇到問題。 該視圖滾動到選項卡下方,而在選項卡布局中未實現可滾動視圖,如下所示。
http://i46.tinypic.com/2ccmp0w.png
當我把選項卡式布局內的滾動視圖它表明,出現車和不可用的一個小滾動視圖。 如下所示。
http://tinypic.com/r/29ej2ft/6
標簽主機的代碼如下
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:padding="5dp" />
<TabWidget
android:id="@android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
</TabHost>
這是實現了滾動視圖的選項卡的代碼
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/todayScroll"
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical" >
<ExpandableListView
android:id="@+id/ExpList"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:groupIndicator="@null" />
</LinearLayout>
</ScrollView>
非常感謝任何關於如何使內容正確滾動而不妨礙標簽的想法:)謝謝。
我已經嘗試了幾次,但是開始變得非常沮喪。
編輯:這是TabHostActivity文件。
public class TabbedMainActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_main);
TabHost tabHost = getTabHost();
// Tab for todays meals
TabSpec todaysSpec = tabHost.newTabSpec("Todays");
//you could set icon here as well as title
todaysSpec.setIndicator("Todays");
Intent todaysIntent = new Intent(this, TodaysMealsActivity.class);
todaysSpec.setContent(todaysIntent);
// Tab for future meals
TabSpec futureSpec = tabHost.newTabSpec("Future");
futureSpec.setIndicator("Future");
Intent futureIntent = new Intent(this, FutureMealsActivity.class);
futureSpec.setContent(futureIntent);
// Tab for comments
TabSpec commentsSpec = tabHost.newTabSpec("Comments");
commentsSpec.setIndicator("Feedback");
Intent commentsIntent = new Intent(this, CommentsActivity.class);
commentsSpec.setContent(commentsIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(todaysSpec); // Adding todays tab
tabHost.addTab(futureSpec); // Adding future tab
tabHost.addTab(commentsSpec); // Adding comments tab
}
}
干杯,Rmplanner
從評論中進行編輯 :在此處找到了另一種解決方案(OP使用的解決方案)。
在 ScrollView
上使用android:layout_height="fill_parent"
。(或者,由於不建議使用 fill_parent
,請使用android:layout_height="match_parent"
。)
首先,刪除ScrollView
,並用以下內容替換RelativeLayout
:
<RelativeLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_above="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
<TabWidget
android:id="@android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.