forked from youth5201314/banner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I03fa8c717ebb70d13b88f1cb58953d6d42ae0911
- Loading branch information
1 parent
f771d15
commit 6d883ff
Showing
8 changed files
with
118 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.test.banner.ui; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.KeyEvent; | ||
|
||
import com.test.banner.R; | ||
import com.test.banner.adapter.ImageAdapter; | ||
import com.test.banner.bean.DataBean; | ||
import com.youth.banner.Banner; | ||
import com.youth.banner.indicator.CircleIndicator; | ||
import com.youth.banner.util.BannerUtils; | ||
|
||
import butterknife.BindView; | ||
import butterknife.ButterKnife; | ||
|
||
public class TVActivity extends AppCompatActivity { | ||
|
||
private static final String TAG = "banner_log"; | ||
@BindView(R.id.banner) | ||
Banner banner; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_t_v); | ||
ButterKnife.bind(this); | ||
banner.setAdapter(new ImageAdapter(DataBean.getTestData())); | ||
banner.setIndicator(new CircleIndicator(this)); | ||
banner.isAutoLoop(false); | ||
} | ||
|
||
@Override | ||
public boolean onKeyDown(int keyCode, KeyEvent event) { | ||
int count = banner.getItemCount(); | ||
switch (keyCode) { | ||
case KeyEvent.KEYCODE_DPAD_LEFT: | ||
Log.d(TAG, "向左"); | ||
int prev = (banner.getCurrentItem() - 1) % count; | ||
if (prev == 0) { | ||
prev = banner.getRealCount(); | ||
} else if (prev == count - 1) { | ||
prev = 1; | ||
} | ||
banner.setCurrentItem(prev, false); | ||
break; | ||
case KeyEvent.KEYCODE_DPAD_RIGHT: | ||
Log.d(TAG, "向右"); | ||
int next = (banner.getCurrentItem() + 1) % count; | ||
if (next == 0) { | ||
next = banner.getRealCount(); | ||
} else if (next == count - 1) { | ||
next = 1; | ||
} | ||
banner.setCurrentItem(next, false); | ||
break; | ||
} | ||
//如果没有设置指示器,就不用执行下面两行 | ||
int real = BannerUtils.getRealPosition(banner.isInfiniteLoop(), banner.getCurrentItem(), banner.getRealCount()); | ||
banner.getIndicator().onPageSelected(real); | ||
return super.onKeyDown(keyCode, event); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".ui.TVActivity"> | ||
|
||
<TextView | ||
android:id="@+id/textView" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:padding="15dp" | ||
android:text="TV中遥控控制banner切换,因为没有真机测试,所以不确定有没有问题,有测试环境的朋友可以多多反馈,或者修改哈" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintHorizontal_bias="0.5" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<com.youth.banner.Banner | ||
android:id="@+id/banner" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
app:indicator_selected_color="@color/colorPrimary" | ||
app:layout_constraintDimensionRatio="3:1" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/textView" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters