嗨我有一个问题,我可以让扫描仪工作完美,它完美解码但在显示结果它显示图像和网址但我似乎无法得到它所以,如果我点击它或一个按钮来加载它顺便说一句17所以,如果它是一个简单的修复,请不要戳乐趣只是纠正我,我只是想学习开发和Android是最好的方式顺便说一下,我正在使用一个开放的源项目我发现实验
Java文件
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jwetherell.quick_response_code;
import android.view.Display;
import android.view.WindowManager;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
/**
* Example Encoder Activity.
*
* @author Justin Wetherell (phishman3579@gmail.com)
*/
public final class EncoderActivity extends Activity {
private static final String TAG = EncoderActivity.class.getSimpleName();
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.encoder);
// This assumes the view is full screen, which is a good assumption
WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
int smallerDimension = width < height ? width : height;
smallerDimension = smallerDimension * 7 / 8;
try {
QRCodeEncoder qrCodeEncoder = null;
//qrCodeEncoder = new QRCodeEncoder("AT", null, Contents.Type.TEXT, BarcodeFormat.CODABAR.toString(), smallerDimension);
//qrCodeEncoder = new QRCodeEncoder("HI", null, Contents.Type.TEXT, BarcodeFormat.CODE_39.toString(), smallerDimension);
//qrCodeEncoder = new QRCodeEncoder("Hello", null, Contents.Type.TEXT, BarcodeFormat.CODE_128.toString(), smallerDimension);
//qrCodeEncoder = new QRCodeEncoder("1234567891011", null, Contents.Type.TEXT, BarcodeFormat.EAN_13.toString(), smallerDimension);
//qrCodeEncoder = new QRCodeEncoder("12345678", null, Contents.Type.TEXT, BarcodeFormat.EAN_8.toString(), smallerDimension);
//qrCodeEncoder = new QRCodeEncoder("1234", null, Contents.Type.TEXT, BarcodeFormat.ITF.toString(), smallerDimension);
//qrCodeEncoder = new QRCodeEncoder("2345", null, Contents.Type.TEXT, BarcodeFormat.PDF_417.toString(), smallerDimension);
qrCodeEncoder = new QRCodeEncoder("Hello", null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), smallerDimension);
//qrCodeEncoder = new QRCodeEncoder("12345678910", null, Contents.Type.TEXT, BarcodeFormat.UPC_A.toString(), smallerDimension);`
Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
ImageView view = (ImageView) findViewById(R.id.image_view);
view.setImageBitmap(bitmap);
TextView contents = (TextView) findViewById(R.id.contents_text_view);
contents.setText(qrCodeEncoder.getDisplayContents());
setTitle(getString(R.string.app_name) + " - " + qrCodeEncoder.getTitle());
} catch (WriterException e) {
Log.e(TAG, "Could not encode barcode", e);
} catch (IllegalArgumentException e) {
Log.e(TAG, "Could not encode barcode", e);
}
} }
Xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2008 ZXing authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/encode_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="@color/encode_view"
android:orientation="vertical"
android:gravity="center">
<ImageView android:id="@+id/image_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scaleType="center"/>
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center
<TextView android:id="@+id/contents_text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:textColor="@color/contents_text"
android:textSize="18sp"
android:paddingBottom="8dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"/>
</ScrollView>
</LinearLayout>
由于
答案 0 :(得分:1)
将其称为textview。
TextView tv = (TextView) findViewById(R.id.text2);
tv.setMovementMethod(LinkMovementMethod.getInstance());
了解Linkify课程......
这使得所有链接(网址,电话号码等)都可以点击。