我最近才开始在android下开发我喜欢它,但是昨天我遇到了zxing的这个问题,这让我发疯了,我真的无法找到解决方案。我正在使用zxing来扫描QR码,它可以工作,但是当我启动它时扫描仪全屏显示,我希望它显示在一个片段中,而不是整个屏幕。我正在平板电脑上开发一个带有两个片段的应用程序,如下所示
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="@android:style/Theme.NoTitleBar"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.example.mlambole.fragapp.InfoFragment"
android:id="@+id/info_fragment"
android:background="#B89470"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment android:name="com.example.mlambole.fragapp.DetailFragment"
android:id="@+id/detail_fragment"
android:background="#ffffff"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
类DetailFragment占据右侧屏幕的2/3,这是我希望扫描仪显示的地方,仅在这些2/3中。
DetailFragment类看起来像现在一样
public class DetailFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.detail_view, container, false);
Button buttonScan = (Button) view.findViewById(R.id.button_scan);
buttonScan.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
clickScan(v);
}
});
return view;
}
public void clickScan(View view)
{
IntentIntegrator integrator = IntentIntegrator.forFragment(this);
integrator.initiateScan(IntentIntegrator.QR_CODE_TYPES);
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
System.out.println("onActivityResult");
if (scanResult != null) {
String scanContent = scanResult.getContents();
String scanFormat = scanResult.getFormatName();
}
}
}
MainActivity
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().hide();
setContentView(R.layout.main_screen);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
我使用Android Studio和Zxing与Maven一起使用
repositories {
mavenCentral()
maven {
url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
}
}
dependencies {
// Supports Android 4.0.3 and later (API level 15)
compile 'com.embarkmobile:zxing-android-minimal:2.0.0@aar'
// Supports Android 2.1 and later (API level 7), but not optimal for later Android versions.
// If you only plan on supporting Android 4.0.3 and up, you don't need to include this.
compile 'com.embarkmobile:zxing-android-legacy:2.0.0@aar'
// Convenience library to launch the scanning and encoding Activities.
// It automatically picks the best scanning library from the above two, depending on the
// Android version and what is available.
compile 'com.embarkmobile:zxing-android-integration:2.0.0@aar'
// Version 3.0.x of zxing core contains some code that is not compatible on Android 2.2 and earlier.
// This mostly affects encoding, but you should test if you plan to support these versions.
// Older versions e.g. 2.2 may also work if you need support for older Android versions.
compile 'com.google.zxing:core:3.0.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
那里有一个zxing天才吗?请
由于