2015-02-24 395 views
0

我有一個問題滾動條在我的佈局。 我的佈局包含一個包含兩個佈局的滾動條。第一個佈局具有靜態高度。第二個拉特包含tabHost爲tabgroup。第二個佈局也包含Expandable Gridview。ScrollView從tabbar開始,但需要從佈局的頂部滾動

問題是,我加載我的佈局時,,它直接顯示Tabbar並隱藏第一個佈局。我們可以滾動但最初我需要顯示頂部佈局,而不是tabHost。任何人都可以幫我解決這個問題嗎?

在此先感謝...

我加入了從XML文件我的代碼段。

<ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/header" 
    android:fillViewport="true" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <RelativeLayout 
      android:id="@+id/relay1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:focusable="true" > 

      <include 
       android:id="@+id/cover" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       layout="@layout/coverphoto" /> 

      <ImageView 
       android:id="@+id/ximg_logo" 
       android:layout_width="70dip" 
       android:layout_height="70dip" 
       android:layout_below="@+id/cover" 
       android:layout_marginLeft="16dip" 
       android:layout_marginTop="-42dip" /> 

      <TextView 
       android:id="@+id/xtxt_name" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignBottom="@+id/ximg_logo" 
       android:layout_marginLeft="5dip" 
       android:layout_toRightOf="@+id/ximg_logo" 
       android:ellipsize="end" 
       android:ems="5" 
       android:singleLine="true" 
       android:textColor="@color/sixty_black" 
       android:textSize="20sp" > 

       <requestFocus /> 
      </TextView> 

      <Button 
       android:id="@+id/xbtn_follow" 
       style="@style/follow_button_normal" 
       android:layout_width="95dip" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:layout_below="@+id/cover" 
       android:layout_marginRight="7dip" 
       android:background="@drawable/buttons_shape_fill_orange" 
       android:text="@string/str_follow" /> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignBottom="@+id/cover" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentTop="true" 
       android:background="@color/fifty_black" 
       android:orientation="vertical" 
       android:paddingLeft="3dip" 
       android:paddingRight="3dip" 
       android:weightSum="3" > 

       <RelativeLayout 
        android:id="@+id/xlay_following" 
        android:layout_width="match_parent" 
        android:layout_height="0dip" 
        android:layout_alignParentTop="true" 
        android:layout_marginTop="10dip" 
        android:layout_weight="1" 
        android:onClick="following" > 

        <TextView 
         android:id="@+id/xtxt_imfollowing" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentTop="true" 
         android:layout_centerHorizontal="true" 
         android:textColor="@color/white" 
         android:textSize="18sp" /> 

        <TextView 
         android:id="@+id/xtxt_imfollowing_text" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_below="@+id/xtxt_imfollowing" 
         android:layout_centerHorizontal="true" 
         android:padding="5dip" 
         android:text="@string/str_im_following" 
         android:textColor="@color/white" 
         android:textSize="14sp" /> 
       </RelativeLayout> 

       <RelativeLayout 
        android:id="@+id/xlay_follower" 
        android:layout_width="match_parent" 
        android:layout_height="0dip" 
        android:layout_weight="1" 
        android:onClick="follower" > 

        <TextView 
         android:id="@+id/xtxt_myfollower" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_centerHorizontal="true" 
         android:layout_marginTop="10dip" 
         android:textColor="@color/white" 
         android:textSize="18sp" /> 

        <TextView 
         android:id="@+id/xtxt_myfollowers_text" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_below="@+id/xtxt_myfollower" 
         android:layout_centerHorizontal="true" 
         android:padding="5dip" 
         android:text="@string/str_myfollowers" 
         android:textColor="@color/white" 
         android:textSize="14sp" /> 
       </RelativeLayout> 

       <RelativeLayout 
        android:id="@+id/xlay_interests" 
        android:layout_width="match_parent" 
        android:layout_height="0dip" 
        android:layout_alignParentBottom="true" 
        android:layout_below="@+id/xlay_follower" 
        android:layout_centerHorizontal="true" 
        android:layout_weight="1" > 

        <TextView 
         android:id="@+id/xtxt_interests" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_centerHorizontal="true" 
         android:layout_marginTop="10dip" 
         android:textColor="@color/white" 
         android:textSize="18sp" /> 

        <TextView 
         android:id="@+id/xtxt_interests_text" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_below="@+id/xtxt_interests" 
         android:layout_centerHorizontal="true" 
         android:paddingBottom="5dip" 
         android:text="@string/str_interest" 
         android:textColor="@color/white" 
         android:textSize="14sp" /> 
       </RelativeLayout> 
      </LinearLayout> 

      <RelativeLayout 
       android:id="@+id/xrl_msg" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:background="@color/fifty_black" 
       android:padding="10dip" > 

       <ImageView 
        android:id="@+id/ximg_message" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true" 
        android:src="@drawable/ic_msg" /> 
      </RelativeLayout> 
     </RelativeLayout> 

     <RelativeLayout 
      android:id="@+id/relay2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/relay1" 
      android:layout_marginTop="10dip" > 

      <TabHost 
       android:id="@android:id/tabhost" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" > 

       <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" 
         android:layout_marginTop="20dip" > 
        </TabWidget> 

        <View 
         android:layout_width="match_parent" 
         android:layout_height="1dip" 
         android:background="@color/orange" /> 

        <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:orientation="vertical" > 
         </LinearLayout> 

         <LinearLayout 
          android:id="@+id/tab2" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:orientation="vertical" > 
         </LinearLayout> 

         <LinearLayout 
          android:id="@+id/tab3" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:orientation="vertical" > 
         </LinearLayout> 
        </FrameLayout> 
       </LinearLayout> 
      </TabHost> 
     </RelativeLayout> 
    </RelativeLayout> 
</ScrollView> 
+0

我認爲它有幫助,如果你只是發佈完整的佈局,除非它太大,希望沒有。 – 2015-02-24 09:59:04

+0

我需要從上到下滾動。所以我認爲「match_parent」不是寬度問題。在Height中,我只給了wrap_content。我有我的第二個佈局tabHost。這可能是我的問題。如果我使用tabHost,則滾動位置從tabHost移開。請爲我提供一些示例,它應該包含佈局下面的佈局,它應該包含tabHost與gridView項目 – 2015-03-02 07:32:05

+0

嗨,我已經更新了我的佈局xml ...你能建議我一個解決方案? – 2015-03-02 07:58:02

回答

0

當然,RelativeLayout rl1與r12重疊。它們都是layout_width上的match_parent。您需要使用android:layout_alignParentTopandroid:layout_alignParentLeft="true"將這兩個佈局與左/右或頂部/底部對齊。 但是,您無法將它用於RelativeLayout。它用於RelativeLayout或LinearLayout中的UI元素。

由於您沒有發佈完整的佈局文件與您的選項卡元素或任何用戶界面,我不能給你任何XML示例。

+0

嗨,我已經更新了我的佈局xml ...你能給我一個解決方案嗎? – 2015-03-02 07:57:42

0

我有一個類似的問題,一個辦法是對我的佈局工作是要改變高度和能見度像下面(使用你的佈局模式作爲一個很好的例子):

<RelativeLayout 
    android:id="@+id/relay1" 
    android:layout_width="match_parent" 
    android:focusable="true" 

    android:layout_height="0dp" 
    android:visibility="gone" 
    > 

通知的機器人:layout_height知名度。當然,我知道你不希望你的第一個佈局總是被完全隱藏。但是這是主意,你可以用你的第二個佈局繼電器2做同樣的事情。

下面是一個示例代碼,用於動態地隱藏/顯示佈局。對象relayLayout是您的relay1視圖。

if "hide the layout" { 
    relayLayout.setVisibility(LinearLayout.GONE); 
} 
else { 
    relayLayout.setVisibility(LinearLayout.VISIBLE); 
} 

通知setVisibility和有效常數。

現在,示例代碼來設置視圖的高度。這可能是您需要的唯一代碼,可能實際上效果更好。

ViewGroup.LayoutParams layoutParams = relayLayout.getLayoutParams(); 
layoutParams.height = 0; 
relayLayout.setLayoutParams(layoutParams); 

通知ViewGroup.LayoutParamsheight屬性爲主。在這個代碼中,佈局將隱藏起來,第二個佈局應該上升。

0

另一個解決方案,也許最好的是谷歌的答案顯示/隱藏2種不同的佈局。在您的佈局文件中,我看到了兩種非常不同的佈局設計,因此適用於您的情況。 一個網頁陳述這是Building a Dynamic UI with Fragments。 這是很好的閱讀。

下面是一個示例代碼,使這一設想:

// Create new fragment and transaction 
Fragment newFragment = new ExampleFragment(); 
FragmentTransaction transaction = getFragmentManager().beginTransaction(); 

// Replace whatever is in the fragment_container view with this fragment, 
// and add the transaction to the back stack 
transaction.replace(R.id.fragment_container, newFragment); 
transaction.addToBackStack(null); 

// Commit the transaction 
transaction.commit(); 

的示例代碼是從Fragments

此代碼和佈局設計的一個優點是,您的2個佈局至少在2個文件中是分開的,並且強制分隔以便將來的代碼更改。 玩得開心:-) Tommy Kwee。

+0

我沒有使用片段。只要給我一個從佈局頂部滾動的解決方案。我使用了很多方法,仍然無法獲得解決方案。希望你能幫助我。 – 2015-03-25 05:26:45

+0

奎師那,你的迴應太遲了,現在我不記得是什麼問題了。以前的答案如何?他們有幫助嗎? – 2015-03-25 06:06:32

相關問題