當我使用依賴關係compile 'me.dm7.barcodescanner:zxing:1.9'
而無法訪問zxing文件時,如何更改取景器大小,顏色和其他選項? 我找不到解決此問題的方法。在zxing中更改查看器
1
A
回答
1
您可以通過XML
<com.journeyapps.barcodescanner.BarcodeView
android:id="@+id/zxing_barcode_surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:zxing_framing_rect_height="220dp"
app:zxing_framing_rect_width="250dp" />
<com.journeyapps.barcodescanner.ViewfinderView
android:id="@+id/zxing_viewfinder_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:zxing_possible_result_points="@color/zxing_custom_possible_result_points"
app:zxing_result_view="@color/zxing_custom_result_view"
app:zxing_viewfinder_laser="@color/zxing_custom_viewfinder_laser"
app:zxing_viewfinder_mask="@color/zxing_custom_viewfinder_mask" />
做到這一點還要檢查this post(可能重複這個問題),並another one,如果你想以編程方式更改的行爲。
要訪問的庫功能,您需要將以下添加到您的build.gradle文件:
repositories {
jcenter()
}
dependencies {
compile 'me.dm7.barcodescanner:zxing:1.9.3'
}
和攝像頭的權限添加到您的AndroidManifest.xml文件:
<uses-permission android:name="android.permission.CAMERA" />
1
來改變ViewFinder的顏色。 這些添加到您的項目的colors.xml
<color name="viewfinder_mask">#3F51B5</color>
<color name="viewfinder_laser">#00FFFFFF</color>
<color name="viewfinder_border">#ffFF4081</color>
做出其他更改,如從ZXingScannerView的取景器 去除激光創建一個類,擴展ViewFinderView。重寫方法來自定義UI 。
public class CustomScannerView extends ZXingScannerView {
public CustomScannerView(Context context) {
super(context);
}
@Override
protected IViewFinder createViewFinderView(Context context) {
return new CustomViewFinderView(context);
}
//make changes in CustomViewFinderView to customise the Viewfinder
//Check ViewFinderView class for more modifications
//to change viewFinder's colours override appropriate values in Colors.xml
class CustomViewFinderView extends ViewFinderView {
public CustomViewFinderView(Context context) {
super(context);
setSquareViewFinder(true);
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
// DEFAULT SQUARE DIMENSION RATIO in ViewFinderView is 0.625
// get appropriate Dimension ratio otherwise
float width = displayMetrics.widthPixels * 0.625f;
setBorderLineLength((int)width);
}
@Override
public void drawLaser(Canvas canvas) {
//do nothing for no laser, even remove super call
}
}
}
設置取景器的矩形 使用
super.getFramingRect().set(left, top, right, bottom);
0
如果你想刪除的激光只,這可以簡單地通過禁用Alpha通道動畫完成:
barcodeView = (DecoratedBarcodeView) findViewById(R.id.barcode_scanner);
barcodeView.decodeContinuous(callback);
ViewfinderView viewFinder = barcodeView.getViewFinder();
Field scannerAlphaField = null;
try {
scannerAlphaField = viewFinder.getClass().getDeclaredField("SCANNER_ALPHA");
scannerAlphaField.setAccessible(true);
scannerAlphaField.set(viewFinder, new int[1]);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
相關問題
- 1. 更改cakephp查看flie(.ctp)但瀏覽器中沒有更改
- 2. 在android中更改圖像查看
- 3. 查看更改UITableView更新
- 4. 如何更改Opencv圖像查看器?
- 5. 在委託方法中進行更改時未查看更改
- 6. 在git存儲器中查看已更改的文件
- 7. 在表達式中更改報表查看器顯示值
- 8. 更改編輯器在eclipse indigo中只能查看xml文件
- 9. 如何在角度控制器中查看可更改參數
- 10. 如何在birt查看器中動態更改數據庫url
- 11. 如何在報表查看器中更改「生成報表」
- 12. 在Google文檔中動態更改src嵌入式查看器
- 13. 更改查看操作
- 14. 顛覆:查看更改
- 15. 更改查看位置
- 16. Drupal:更改查看參數
- 17. 如何查看observableArray更改
- 18. AnkhSVN查看最近更改
- 19. 更改ListView模板/查看
- 20. 收聽TabBar查看更改
- 21. 查看VS2010/TFS中的更改
- 22. 更改查看框後居中對象
- 23. 無法更改tableView中的indicatorView.backgroundColor查看
- 24. 如何查看vmmap中的更改?
- 25. 查看svn分支中的更改
- 26. 查看更改工作不在一起
- 27. 查看更改「在提交」Rails
- 28. 如何在github中查看本地未修改的更改
- 29. 更新列表 - 查看模型更改
- 30. 查看不更新爲基類更改
但如何我可以安裝它來訪問它的類嗎?我是Android開發新手。 – codddeer123
@ codddeer123只需在Gradle中添加依賴項'compile'me.dm7.barcodescanner:zxing:1.9.3''到應用程序模塊。您也可以使用[Github項目](https://github.com/dm77/barcodescanner#installation)中的安裝指南。在開始同步項目之後,您可以使用庫中的類和視圖。外部庫中的 – Tim
- > zxing-1.9?請只查看BuildConfig和ZXingScannerView – codddeer123