import
com.dreamwin.pinshan.player.ExtendedHorizontalScrollView;
import
com.dreamwin.pinshan.player.ExtendedHorizontalScrollView.IScrollStateListener;
import com.dreamwin.pinshan.thread.ThreadPoolWrap;
import com.dreamwin.pinshan.utils.Utils;
@SuppressLint("HandlerLeak")
public class Channel extends Activity {
private ImageButton aboutBtn;
private ImageButton searchBtn;
private ExtendedHorizontalScrollView
scrollView;
private ImageView leftbtn;
private ImageView rightBtn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.channel);
findAllViews(); // 找到所有控件
initOnClickerListener();
channels = new ArrayList();
videos = new ArrayList();
// 判断网络情况
if (!Utils.checkNetworkAvalible()) {
channelListLayout.removeAllViews();
netError = (RelativeLayout)
LayoutInflater.from(Channel.this)
.inflate(R.layout.net_error, null);
ImageView imageView = (ImageView) netError
.findViewById(R.id.network_error_image);
imageView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
init();
}
});
channelListLayout
.addView(netError, Utils.getRelativeLayoutParams());
return;
}
init();
}
private void addChannelTags() {
if (MyChannelLsit.lists.size() == 0) {
netLoading.setVisibility(View.GONE);
channelListLayout.removeAllViews();
return;
}
channels.addAll(MyChannelLsit.lists);
setChannelBtnListener();
setChannelsTags();
}
private void init() {
addChannelTags();
// 初始化时,应选中电影频道
if (!Utils.checkNetworkAvalible()) {
channelListLayout.removeAllViews();
netError = (RelativeLayout)
LayoutInflater.from(Channel.this)
.inflate(R.layout.net_error, null);
ImageView imageView = (ImageView) netError
.findViewById(R.id.network_error_image);
imageView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
init();
}
});
channelListLayout
.addView(netError, Utils.getRelativeLayoutParams());
return;
}
channelListLayout.removeAllViews();
btnShiShang.requestFocusFromTouch();
btnShiShang.setSelected(true);
btnZuiXin.setSelected(true);
channelListLayout.addView(netLoading,
Utils.getRelativeLayoutParams());
}
private void setChannelBtnListener() {
channelBtnListener = new
ChannelBtnListener(getApplication(),
videoListView, channelListLayout, netLoading, netError,
id,
channelSize, channels, videos);
btnZuiXin.setOnClickListener(channelBtnListener);
btnHot.setOnClickListener(channelBtnListener);
}
private void findAllViews() {
leftbtn=(ImageView) findViewById(R.id.left_btn);
rightBtn=(ImageView) findViewById(R.id.right_btn);
scrollView=(ExtendedHorizontalScrollView)
findViewById(R.id.channel_tag_hv);
scrollView.setScrollStateListener(new IScrollStateListener()
{
public void onScrollMostRight() {
rightBtn.setVisibility(View.GONE);
leftbtn.setVisibility(View.VISIBLE);
}
public void onScrollMostLeft() {
leftbtn.setVisibility(View.GONE);
}
public void onScrollFromMostLeft() {
leftbtn.setVisibility(View.VISIBLE);
}
public void onScrollFromMostRight() {
rightBtn.setVisibility(View.VISIBLE);
}
});
}
}
相关实现参考自:
我使用水平滚动视图,并且在视图上动态的添加项目。如果项目的数量超过能在屏幕上能显示的数量,我想用如下图显示的,用箭头形式水平滚动来显示这些项目。怎么实现呢?
这是我使用的XML代码:
android:layout_width="wrap_content"
android:scrollbars="none"
android:id="@+id/app_category"
android:layout_below="@+id/top_layout"
android:background="@drawable/minitopbar"
android:layout_height="30dp">
android:orientation="horizontal"
android:id="@+id/app_category_scroll_layout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"/>
11-26 14:42 提问
您认为此问题: 有用 (0)收藏 (0)
0
A.你应该创建自己的类,然后继承HorizontalScrollView:
public class ExtendedHorizontalScrollView extends HorizontalScrollView {
private IScrollStateListener scrollStateListener;
public HorizontalScrollViewForMenu(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public HorizontalScrollViewForMenu(Context context, AttributeSet attrs) {
super(context, attrs);
}
public HorizontalScrollViewForMenu(Context context) {
super(context);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
prepare();
}
private void prepare() {
if (scrollStateListener != null) {
View content = this.getChildAt(0);
if (content.getLeft() >= 0)
scrollStateListener.onScrollMostLeft();
if (content.getLeft() < 0)
scrollStateListener.onScrollFromMostLeft();
if (content.getRight() <= getWidth())
scrollStateListener.onScrollMostRight();
if (content.getLeft() > getWidth())
scrollStateListener.onScrollFromMostRight();
}
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (scrollStateListener != null) {
if (l == 0)
scrollStateListener.onScrollMostLeft();
else if (oldl == 0)
scrollStateListener.onScrollFromMostLeft();
int mostRightL = this.getChildAt(0).getWidth() - getWidth();
if (l >= mostRightL)
scrollStateListener.onScrollMostRight();
if (oldl >= mostRightL && l < mostRightL)
scrollStateListener.onScrollFromMostRight();
}
}
public void setScrollStateListener(IScrollStateListener listener) {
scrollStateListener = listener;
}
public interface IScrollStateListener {
void onScrollMostLeft();
void onScrollFromMostLeft();
void onScrollMostRight();
void onScrollFromMostRight();
}
}
B.使用它来定义布局
..... />
android:layout_width="0px"
android:layout_weight="1"
android:fadingEdge="none"
....>
android:layout_width="match_parent"
android:layout_height="match_parent" />
..... />
C.当不能水平滚动的时候,给箭头添加以下逻辑:
((ExtendedHorizontalScrollView)findViewById(R.id.scroller)).setScrollStateListener(new IScrollStateListener() {
public void onScrollMostRight() {
((View) scroller.getParent()).findViewById(R.id.navigation_right).setVisibility(View.INVISIBLE);
}
public void onScrollMostLeft() {
((View) scroller.getParent()).findViewById(R.id.navigation_left).setVisibility(View.INVISIBLE);
}
public void onScrollFromMostLeft() {
((View) scroller.getParent()).findViewById(R.id.navigation_left).setVisibility(View.VISIBLE);
}
public void onScrollFromMostRight() {
((View) scroller.getParent()).findViewById(R.id.navigation_right).setVisibility(View.VISIBLE);
}
});
11-30 10:09 回答
您认为此回答: 有用 (0)收藏 (0)
0
一个简单的方法是让scrollview没有边缘,然后在scrollview上面或下面添加带箭头的图像。
android:layout_height="fill_parent">
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:fadingEdge="none"
/>
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:background="@drawable/background_effect"/>