我试图理解一些东西。我看到的一件奇怪的事情是,当我wrap_content输入宽度和高度时,图像比插入的图像的实际 px(像素)尺寸大。为什么呢?
我的代码wrap_content:
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:src="@drawable/header" />
Run Code Online (Sandbox Code Playgroud)
这就是我的代码,具有图像的精确像素大小:
<ImageView
android:id="@+id/imageView1"
android:layout_width="378px"
android:layout_height="155px"
android:adjustViewBounds="false"
android:src="@drawable/header" />
Run Code Online (Sandbox Code Playgroud)
如您所见,这是确切的像素大小:
这是为什么?我认为wrap_content应该将视图包装到内容大小,为什么它在屏幕上更大?
我有ScrollView另一个视图(带Buttons).该ScrollView走的是整个屏幕,并模糊是它下面的视图.
在我的应用程序的某个时刻,我需要ScrollView禁用(但仍然可见)并将所有触摸事件传输到Buttons下面的ScrollView.我怎样才能做到这一点?有些视图Buttons在禁用时会自动执行此操作,但a ScrollView不会这样做.
我有一个ArrayAdapter,我需要获得应用程序的共享首选项,以便用它做一些事情.我的问题我不能得到共享的偏好.那就是我的代码:
public class MobileArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
private static SharedPreferences prefs;
private String firstBtName = "";
private String secondBtName = "";
private String thirdBtName = "";
public MobileArrayAdapter(Context context, String[] values) {
super(context, R.layout.list, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
prefs = getSharedPreferences("MYPREFS", 0); // ERROR **************
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.list, parent, false);
TextView …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用FragmentStatePagerAdapter.这是我的适配器:
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
List<FeedItem> posts = FeedListFragment.getPosts();
public ScreenSlidePagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
@Override
public Fragment getItem(int position) {
FeedItem post = posts.get(position);
String url = post.getUrl();
String title = post.getTitle();
String imagUrl = null;
if (post.getType() == FeedItem.ARTICLE_VIEW_TYPE) {
imagUrl = posts.get(position).getArticle().getImageUrl();
}
ScreenSlidePageFragment fragment = new ScreenSlidePageFragment(url, title, imagUrl);
fragment.setPostsFragmentOnItemClickListener(PostActivity.this);
return fragment;
}
@Override
public int getCount() {
return posts.size();
}
}
Run Code Online (Sandbox Code Playgroud)
我需要的是跳转到此适配器中的特定位置,以及跳转到下一个和上一个视图的能力.我怎样才能做到这一点?谢谢!
当蓝牙与设备断开连接时,我正试图"捕获".我正在使用此代码:
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)){
deleteNotification();
setWarningState(WarningState.RedWarning);
showNotification("You are parked");
Run Code Online (Sandbox Code Playgroud)
但是当我通过关闭远程设备或通过关闭手机中的蓝牙切换来断开蓝牙时,它将不会进入此状态.
当我使用这个:
BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)
Run Code Online (Sandbox Code Playgroud)
它的工作正常(当连接完成时).为什么这样,我怎么能让它发挥作用?谢谢!
我正在做一个标签布局。我的问题是标签之间的空间很小。

多数民众赞成我的XML:
<TabHost
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerPadding="0dp"
android:fitsSystemWindows="true"
android:gravity="fill"
android:orientation="horizontal"
android:showDividers="none"
android:visibility="visible" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/left_tab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:showDividers="none" >
Run Code Online (Sandbox Code Playgroud)
多数民众赞成在我的Java代码:
public void CreateTabs(ImageView leftI, ImageView rightI, ImageView middleI, TabHost tabH) {
leftI.setImageDrawable(getResources().getDrawable(R.drawable.btn_tab_news));
leftI.setScaleType(ScaleType.FIT_XY);
rightI.setImageDrawable(getResources()
.getDrawable(R.drawable.btn_tab_calender));
rightI.setScaleType(ScaleType.FIT_XY);
middleI.setImageDrawable(getResources()
.getDrawable(R.drawable.btn_tab_press));
middleI.setScaleType(ScaleType.FIT_XY);
tabH.setup();
TabSpec specs = tabH.newTabSpec("tag1");
specs.setContent(R.id.right_tab);
specs.setIndicator(rightI);
tabH.addTab(specs);
specs = tabH.newTabSpec("tag2");
specs.setContent(R.id.middle_tab);
specs.setIndicator(middleI);
tabH.addTab(specs);
specs = tabH.newTabSpec("tag3");
specs.setContent(R.id.left_tab);
specs.setIndicator(leftI);
tabH.addTab(specs);
}
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况,我该如何解决?谢谢!
我在我的应用程序中使用Proguard.有一天,它突然开始给我这些错误.这就像Proguard找不到我的任何课程.我可以做些什么来触发这个,我该如何解决这个问题?这是我的proguard设置:
-keepattributes Signature
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-libraryjars adt-bundle-windows-x86_64/sdk/extras/android/support/v4/android-support-v4.jar
-libraryjars libs/FlurryAgent.jar
-libraryjars libs/libGoogleAnalyticsV2.jar
-libraryjars libs/crittercism_v3_0_7_sdkonly.jar
-libraryjars libs/gson-2.2.2.jar
-libraryjars libs/urbanairship-lib-2.1.4.jar
# Gson
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# Gson deserialization uses introspection to get the json entry names for the field names,
# so we do not want to change them.
-keep class com.ftbpro.data.model.** …Run Code Online (Sandbox Code Playgroud)