2012-06-15 4 views
4

나는 5 개의 탭이있는 TabWidget이 있습니다. : "1", "2", "3", "4", "5". 은 HorizontalScrollView입니다. 이제 각 방향에 하나의 화살표 (< 및>)가 표시되어 해당 방향으로 더 많은 탭이 있음을 나타냅니다 (보기에는 현재 보이지 않음). 첫 번째 탭은 다음 현재보기에 (를 화살표가 표시되어야합니다 (<)를 왼쪽으로 마지막 탭이 표시되지 않는 경우 (현재보기) 보이지 않는 경우TabWidget의 특정 "탭"이 현재보기에서 표시되는지 여부를 확인할 수 있습니까?

지금 내가하고 싶은 것입니다) 오른쪽 화살표가 표시되어야하고 두 탭이 모두 보이지 않으면 (현재보기에 ) 두 화살표가 모두 표시되어야합니다. 내 두 탭은 시작에 보이지 않는,

if (horizontablscrollview.getLeft == 0) 
{ 
    arrowRight.setVisiblity(View.VISIBLE) 
    arrowLeft.setVisiblity(View.INVISIBLE) 
} 
else if(horizontablscrollview.getRight == 0) 
{ 
    arrowLeft.setVisiblity(View.VISIBLE) 
    arrowRight.setVisiblity(View.INVISIBLE) 
} 

else if (horizontablscrollview.getRight == 0 && horizontablscrollview.getLeft == 0) 
{ 
    arrowRight.setVisiblity(View.VISIBLE) 
    arrowLeft.setVisiblity(View.VISIBLE) 
} 

하지만이 작동하지 않습니다 : 나는 함께 그 일을 시도

내 XML은 다음과 같습니다 ..

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#ffffff" > 

    <RelativeLayout 
     android:id="@+id/RL_Header" 
     android:layout_width="fill_parent" 
     android:layout_height="50dip" 
     android:layout_marginBottom="3dip" 
     android:background="@drawable/gradient" > 

     <ImageButton 
      android:id="@+id/btn_Home" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="3dp" 
      android:background="@android:color/transparent" 
      android:contentDescription="@string/description_home" 
      android:onClick="onHomeButtonClick" 
      android:src="@drawable/title_home" /> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="5dip" 
      android:layout_marginTop="5dip" 
      android:background="@android:color/transparent" 
      android:contentDescription="@string/description_about" 
      android:onClick="onClickAbout" 
      android:src="@drawable/title_about" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/FL_Tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/RL_Header" > 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/FL_Tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/RL_Header" > 

     <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" 
      android:background="#ffffff" > 

        <ImageView android:id="@+id/arrow_left" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@drawable/i_button" 
         android:layout_alignParentLeft="true"/>    

      <RelativeLayout 
       android:id="@+id/rl_tabs" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" > 

        <ImageView android:id="@+id/arrow_left" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@drawable/i_button" 
         android:layout_alignParentLeft="true" 
         android:visibility="invisible"/> 

        <ImageView android:id="@+id/arrow_Right" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@drawable/i_button" 
         android:layout_alignParentRight="true" 
         android:visibility="invisible"/>      

       <HorizontalScrollView 
        android:id="@+id/my_scrollView" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:fillViewport="true" 
        android:scrollbars="none" 
        android:layout_toRightOf="@+id/arrow_left" 
        android:layout_toLeftOf="@+id/arrow_Right"> 

        <TabWidget 
         android:id="@android:id/tabs" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:tabStripEnabled="true"/> 
       </HorizontalScrollView> 
      </RelativeLayout> 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:paddingTop="65dip" > 

       <RelativeLayout 
        android:id="@+id/myTabContent" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="50dip" > 

        <TableLayout 
         android:id="@+id/tabSubs" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:background="#ffffff" 
         android:shrinkColumns="*" 
         android:stretchColumns="*" > 

         <TableRow 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:layout_marginBottom="20dip" 
          android:layout_marginTop="20dip" 
          android:gravity="center_horizontal" > 

          <Button 
           android:id="@+id/btntestno1" 
           android:layout_weight="1" 
           android:gravity="center" 
           android:padding="20dip" 
           android:text="Test 1" 
           android:textColor="#000000" /> 

          <Button 
           android:id="@+id/btntestno2" 
           android:layout_weight="1" 
           android:gravity="center" 
           android:padding="20dip" 
           android:text="Test 2" 
           android:textColor="#000000" /> 
         </TableRow> 

         <TableRow 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:layout_marginBottom="20dip" 
          android:gravity="center_horizontal" > 

          <Button 
           android:id="@+id/btntestno3" 
           android:layout_weight="1" 
           android:gravity="center" 
           android:padding="20dip" 
           android:text="Test 3" 
           android:textColor="#000000" /> 

          <Button 
           android:id="@+id/btntestno4" 
           android:layout_weight="1" 
           android:gravity="center" 
           android:padding="20dip" 
           android:text="Test 4" 
           android:textColor="#000000" /> 
         </TableRow> 

         <TableRow 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:layout_marginBottom="20dip" 
          android:gravity="center_horizontal" > 

          <Button 
           android:id="@+id/btntestno5" 
           android:layout_weight="1" 
           android:gravity="center" 
           android:padding="20dip" 
           android:text="Test 5" 
           android:textColor="#000000" /> 

          <Button 
           android:id="@+id/btntestno6" 
           android:layout_weight="1" 
           android:gravity="center" 
           android:padding="20dip" 
           android:text="Test 6" 
           android:textColor="#000000" /> 
         </TableRow> 
        </TableLayout> 
       </RelativeLayout> 
      </FrameLayout> 
     </TabHost> 
    </RelativeLayout> 

</RelativeLayout> 

하나를 도와 주시면 대단히 감사하겠습니다.

답변

2

하나의 해결책은 HorizontalScrollView 클래스를 소유하고 스크롤을 기반으로 ImageViews을 표시하는 것입니다 (아래 코드를 많이 테스트하지는 않았지만 테스트를 거쳤 음). 활동의

SpecialScroll hsv = (SpecialScroll) findViewById(R.id.my_scrollView); 
hsv.setPositionListener(this); // I made the activity implement the SpecialScroll.PositionListener interface 

과 :

public class SpecialScroll extends HorizontalScrollView { 

    public interface PositionListener { 

     public void onLeftArrowRequired(boolean required); 

     public void onRightArrowRequired(boolean required); 

     public View implementScrolledView(); 
    } 

    private PositionListener listener; 

    public void setPositionListener(PositionListener listener) { 
     this.listener = listener; 
    } 

    public SpecialScroll(Context context) { 
     super(context); 
    } 

    public SpecialScroll(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    public SpecialScroll(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    @Override 
    protected void onScrollChanged(int l, int t, int oldl, int oldt) { 
     super.onScrollChanged(l, t, oldl, oldt); 
     if (l == 0) { 
      listener.onLeftArrowRequired(false); 
     } else { 
      listener.onLeftArrowRequired(true); 
     } 
     View v = listener.implementScrolledView(); 
     Rect r = new Rect(); 
     v.getDrawingRect(r); 
     if ((r.width() - l) == getWidth()) { 
      listener.onRightArrowRequired(false); 
     } else { 
      listener.onRightArrowRequired(true); 
     } 

    } 

} 

는 그런 활동의 onCreate 방법으로 당신이 할 수 있습니다 :

//... 
      <RelativeLayout 
       android:id="@+id/rl_tabs" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" > 

        <ImageView android:id="@+id/arrow_left" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@drawable/i_button" 
         android:layout_alignParentLeft="true" 
         android:visibility="gone"/> 

        <ImageView android:id="@+id/arrow_Right" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@drawable/i_button" 
         android:layout_alignParentRight="true" 
         />      

       <com.your.package.here.SpecialScroll 
        android:id="@+id/my_scrollView" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:fillViewport="true" 
        android:scrollbars="none" > 

        <TabWidget 
         android:id="@android:id/tabs" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:tabStripEnabled="true"/> 
       </com.your.package.here.SpecialScroll> 
      </RelativeLayout> 

//... 

SpecialScroll 클래스는 다음과 같이 표시됩니다 귀하의 레이아웃은 다음과 같이 표시됩니다 PositionListener 인터페이스의 구현은 다음과 같습니다.

@Override 
    public void onLeftArrowRequired(boolean required) { 
     if (required) { 
      ((ImageView) findViewById(R.id.arrow_left)) 
        .setVisibility(View.VISIBLE); 
     } else { 
      ((ImageView) findViewById(R.id.arrow_left)) 
        .setVisibility(View.GONE); 
     } 
    } 

    @Override 
    public void onRightArrowRequired(boolean required) { 
     if (required) { 
      ((ImageView) findViewById(R.id.arrow_right)) 
        .setVisibility(View.VISIBLE); 
     } else { 
      ((ImageView) findViewById(R.id.arrow_right)) 
        .setVisibility(View.GONE); 
     } 
    } 

    @Override 
    public View implementScrolledView() { 
     return findViewById(android.R.id.tabs); 
    } 
+0

당신이 여기에 올린 코드는 내가 원하는 것에 가깝지만 의도적으로 작동하지 않습니다. 나는이 새로운 일종의이며 올바르게 작동하도록 코드를 조작하는 방법을 모르겠다. 그것이 작동하도록하기 위해 당신이 그것을 조사 할 수 있다면 그것은 나의 요구이다. 나는 크게 감사 할 것이다. 그리고 그 문제를 유감스럽게 생각합니다. – ark

+0

@ user1395649 당신은 내 코드가 지금 어떻게 작동하고 어떻게 대신 일하고 싶었는지 언급해야합니다.나는 마음을 읽을 수 없다 :) – Luksprog

+0

롤 죄송합니다, 무슨 일이 나는 극단적 인 권리를 스크롤 할 때, 왼쪽 화살표 (보이게 될 예정이다)가 보이지 않게되고 오른쪽 (사라져야한다)이 거기에 머무르게됩니다. 가운데 부분 (화살표가 모두 보일 곳)은 완벽하게 작동합니다. 이제 오른쪽에서 극한의 왼쪽으로보기를 스크롤하면 오른쪽과 왼쪽의 두 화살표가 그대로 남아 있습니다 (극단적 인 왼쪽에있을 때 왼쪽이 사라져야 함). 나는 내가 여기에 없다면 이것을 정확하게 설명하기를 바랍니다. 빠른 회신을 주셔서 감사합니다 (: – ark

0

이것은 우아한 해결책은 아니지만 가장 왼쪽 탭의 x 좌표가 0보다 작 으면 왼쪽 화살표를 표시하고 가장 오른쪽 탭의 x와 너비가 화면 너비보다 큰 경우 오른쪽 탭을 표시 할 수 있습니다. .

+0

내가보기에 탭이 3 개 (4th 5th and 6th)이면 화살표가 4th 탭 옆에 표시되어야합니다. 특정 탭이보기에 표시되는지 여부를 알 수 있는지 여부를 알고 싶기 때문에 화살표의 가시성을 적절하게 설정할 수 있습니다. – ark

+0

내가 무엇을 묻고 있는지 이해하는지 모르겠다. 4, 5, 6 번째 탭이 보이면 제 제안이 효과가 있습니다. 왼쪽 화살표가 필요하다는 것을 알 것입니다. 화살표를 화면 가장자리 또는 단추에 구체적으로 연결하고 있습니까? 그들은 화면에 묶여 있다면, 나는 아무런 관심을 보이지 않는다. –

+0

아래의 내 대답을 확인해 주시겠습니까? 여기 내 의견과 함께 제 코드를 게시 할 수 없습니다. 그 죄송합니다. – ark

관련 문제