2012-03-21 90 views
1

我在我的应用程序中有一个水平滚动视图。在滚动视图的任一侧,我希望保留一个左和右箭头按钮(在下面的ibRft & ibRight),它应该始终可见,并且在任何时间点都不应该隐藏在水平滚动视图图像之后。修复水平滚动视图两侧的左右箭头按钮

面对我的问题是:

  1. 不知何故,水平滚动视图那种重叠的两个按钮。

  2. 另外,我没有看到任何事情发生时,我设置按钮的onclick监听器。我在某处看到,当我们有一个水平滚动视图时,这是一个问题。

请帮忙。

<?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" > 


    <RelativeLayout 
     android:id="@+id/RelBt" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:text="NEWS" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:text="LIVE T.V." /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:text="YOUTH" /> 
    </RelativeLayout> 

    <TextView 
     android:id="@+id/tvtmp" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:text="Video will come up here" /> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/RelBt" 
     android:layout_below="@+id/tvtmp" > 

     <ImageButton 
      android:id="@+id/ibLeft" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:src="@drawable/ic_launcher" /> 

     <ImageButton 
      android:id="@+id/ibRight" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:src="@drawable/ic_launcher" /> 

     <HorizontalScrollView 
      android:id="@+id/hsv" 
      android:layout_width="wrap_content" 
      android:fadingEdgeLength="100dp" 
      android:layout_height="wrap_content" > 

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

       <ImageView..../> 
<ImageView..../> 
<ImageView..../> 
<ImageView..../> 
<ImageView..../> 

          </RelativeLayout> 
     </HorizontalScrollView> 
    </RelativeLayout> 

</RelativeLayout> 

Java文件是

public class Main extends Activity implements OnClickListener{ 

    HorizontalScrollView hSV; 
    ImageButton ibLeft,ibRight; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     ibLeft=(ImageButton) findViewById(R.id.ibLeft); 
     ibLeft.setOnClickListener(this); 

     ibRight=(ImageButton) findViewById(R.id.ibRight); 
     ibRight.setOnClickListener(this); 

     hSV=(HorizontalScrollView) findViewById(R.id.hsv); 

    } 

    @Override 
    public void onClick(View v) { 
     if(v.getId()==R.id.ibLeft){ 
      Toast.makeText(Main.this, "Left", Toast.LENGTH_SHORT).show(); 
     } 
     else if(v.getId()==R.id.ibLeft){ 
      Toast.makeText(Main.this, "Right", Toast.LENGTH_SHORT).show(); 
     } 
    } 

} 

回答

1

将您的HorizontalScrollView相对于你的ImageButtons

//... 
<RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/RelBt" 
     android:layout_below="@+id/tvtmp" > 

     <ImageButton 
      android:id="@+id/ibLeft" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:src="@drawable/ic_launcher" /> 

     <ImageButton 
      android:id="@+id/ibRight" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:src="@drawable/ic_launcher" /> 

     <HorizontalScrollView 
      android:id="@+id/hsv" 
      android:layout_width="wrap_content" 
      android:fadingEdgeLength="100dp" 
      android:layout_toRightOf="@id/ibLeft" 
      android:layout_toLeftOf="@id/ibRight" 
      android:layout_height="wrap_content" > 
//... 

Regardind没有收到他们很可能被HorizontalScrollView覆盖点击事件,也是你的按钮在onClick()方法中,将相同的ID(左侧按钮)设置为两个按钮,左侧和右侧。

+0

fadingEdgeLength不起作用,不包括箭头。 – JPM 2015-11-23 22:35:41

+0

@JPM根据您的图片尺寸计算适当的值。 – Luksprog 2015-11-24 04:33:43

相关问题