我有一个HorizontalScrollView包含一个RelativeLayout.此布局在XML中为空,并在onCreate中从java填充.
我希望这个滚动视图最初位于中间的某个位置RelativeLayout,这比屏幕大.
我试过mHorizScrollView.scrollTo(offsetX, 0);哪个不起作用.我不知道这有什么问题.
我可以发布代码,但它并不真正相关.重要的是一切都是以编程方式完成的(必须:s),并且HorizontalScrollView必须以编程方式设置初始位置.
谢谢阅读.请告诉我您是否需要更多详细信息,或者这是否不够清楚.
我有一个使用自定义适配器的ListView.自定义适配器的getView使用了所有建议的做法:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
SuscriptionsViewsHolder holder;
ItemInRootList item = mItemsInList.get(position);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.label, null);
holder = new SuscriptionsViewsHolder();
holder.label = (TextView) convertView.findViewById(R.id.label_label);
holder.icon = (ImageView) convertView.findViewById(R.id.label_icon);
convertView.setTag(holder);
} else {
holder = (SuscriptionsViewsHolder) convertView.getTag();
}
String text = String.format("%1$s (%2$s)", item.title, item.unreadCount);
holder.label.setText(text);
holder.icon.setImageResource(item.isLabel ? R.drawable.folder : R.drawable.file );
return convertView;
}
Run Code Online (Sandbox Code Playgroud)
但是当我滚动时,由于垃圾收集量很大,它很迟钝:
GC_EXTERNAL_ALLOC freed 87K, 48% free 2873K/5447K, external 516K/519K, paused 30ms
GC_EXTERNAL_ALLOC freed 7K, 48% free …Run Code Online (Sandbox Code Playgroud) 这真让我抓狂.即使使用推荐的做法,我也不知道如何从配置活动更新app小部件.为什么不在应用程序小部件创建上调用更新方法超出了我的理解.
我想要的是:包含项目集合(带有列表视图)的应用程序小部件.但是用户需要选择一些东西,所以我需要一个配置活动.
配置活动是ListActivity:
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class ChecksWidgetConfigureActivity extends SherlockListActivity {
private List<Long> mRowIDs;
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
private BaseAdapter mAdapter;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setResult(RESULT_CANCELED);
setContentView(R.layout.checks_widget_configure);
final Intent intent = getIntent();
final Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If they gave us an intent without the widget id, just bail.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
mRowIDs = new ArrayList<Long>(); // it's actually loaded …Run Code Online (Sandbox Code Playgroud) 我正在尝试切换到Android Studio和Gradle,但是我在与Studio集成和使用Gradle构建时遇到了一些问题.
git clone来自他们的github位置目前,我所拥有的是:
Main Project
??? GH Lib 1
? ??? <some stuff from the lib>
? ??? library
? ??? AndroidManifest.xml
? ??? res
? ??? src
??? GH Lib 2
? ??? <same structure as the lib 1>
??? GH Lib 3
? ??? <same structure as the lib 1>
??? GH Lib 4
? ??? <same structure as the lib 1>
??? My App folder
??? AndroidManifest.xml
??? res …Run Code Online (Sandbox Code Playgroud) 让我们举个例子:我有一个表单,其中有几个部分,每个部分都有问题.侧面,我有答案映射到问题,他们有另一列,我想在查询时过滤:
所以我有以下实体:
@Entity(tableName = "sections")
public class Section {
@PrimaryKey
public long id;
public String title;
}
@Entity(tableName = "questions")
public class Question {
@PrimaryKey
public long id;
public String title;
public long sectionId;
}
@Entity(tableName = "answers")
public class Answer {
@PrimaryKey
public long id;
public long questionId;
public int otherColumn;
}
Run Code Online (Sandbox Code Playgroud)
在DAO部分,我想要检索所有这些.
这是我想通过此查询填充的POJO:
class SectionWithQuestions {
@Embedded
public Section section;
@Relation(parentColumn = "id", entityColumn = "sectionId", entity = Question.class)
public List<QuestionWithAnswer> questions;
public static class QuestionWithAnswer {
@Embedded …Run Code Online (Sandbox Code Playgroud) 我有一个活动,包含片段'list',点击其中一个项目后会将其自身替换为'content'片段.当用户使用后退按钮时,他再次被带到"列表"片段.
问题是片段处于默认状态,无论我尝试持久化数据.
事实:
public static TheFragment newInstance(Bundle args),setArguments(args)并Bundle args = getArguments()FrameLayout父活动的内部(即不是嵌套片段)setRetainInstance,因为我的活动是主/细节流程,在大屏幕上有2个窗格布局.7"平板电脑有1个纵向画面和2个横向画面.如果我保留'list'片段实例,它会(我认为)搞乱屏幕旋转FragmentTransaction#replace(int, Fragment, String)以相同的ID但不同的标签显示onSaveInstanceState(Bundle),但是这并不总是被框架调用,正如文档所述:"在很多情况下,片段可能会被大部分拆除(例如放置在没有UI显示的后台堆栈上),但是它的状态在其拥有的活动实际上需要保存其状态之前不会被保存."从上面的子弹5中,我猜测片段事务后需要恢复内存的低端设备可能会调用Fragment#onSaveInstanceState(Bundle).但是,在我的测试设备(Galaxy Nexus和Nexus 7)上,框架不会调用该方法.所以这不是一个有效的选择.
那么,我如何保留一些片段数据呢?传递给捆绑Fragment#onCreate,Fragment#onActivityCreated等始终null.
因此,我无法从全新的片段启动到后台堆栈恢复有所作为.
注意:可能的相关/重复问题
我试图layout_behavior在一个元素上设置一个子元素CollapsingToolbarLayout但是从不在iv_header视图上调用行为.当它固定在外面时,例如tv_follow视图,它可以很好地工作.
文档没有明确说明layout_behavior不能在一个AppBarLayout或那个范围内应用CollapsingToolbarLayout我因为它不工作而感到茫然.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="@dimen/full_header_height"
android:focusable="true"
android:focusableInTouchMode="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/iv_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:contentDescription="@null"
app:layout_behavior="com.package.view.HidingBehavior"
app:layout_collapseMode="parallax"
android:src="@drawable/profile_background"/>
<android.support.v7.widget.Toolbar
android:id="@+id/header_toolbar"
android:layout_height="@dimen/action_bar_height"
android:layout_width="match_parent"
android:background="@drawable/toolbar_dark_gradient_half"
android:gravity="top"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<TextView
android:id="@+id/tv_follow"
android:textSize="20sp"
android:textColor="@android:color/white"
android:text="@string/follow"
android:drawableLeft="@drawable/comm_follow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/header"
app:layout_anchorGravity="center"
app:layout_behavior="com.package.view.HidingBehavior"
android:drawablePadding="8dp"
android:gravity="center"
android:visibility="gone"
android:fitsSystemWindows="true"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
行为被从设计支持库中的FloatingActionButton代码中拉出.
public class HidingBehavior extends CoordinatorLayout.Behavior<View>{ …Run Code Online (Sandbox Code Playgroud) android androiddesignsupport android-coordinatorlayout android-collapsingtoolbarlayout
如何确定文件是否为空?该文件由在Windows平台上运行的C程序打开.我想以追加模式打开文件,如果为空,首先打印一个标题.
// Open CSV & write header
report_csv = fopen("SNR.csv", "a+");
if (!report_csv) {
fprintf(stderr, "Unable to open CSV output file...");
return -1;
}
if (!ftell(report_csv)) {
fprintf(report_csv, "Column A;Column B;Column C\n");
}
// ... print data to file
fclose(report_csv);
Run Code Online (Sandbox Code Playgroud)
ftell如果文件不为空,我希望返回当前文件大小,这是因为上面的代码是循环的.
但是,ftell始终返回0并且标题被多次打印.
我知道我可以fopen将其与r和使用fseek/ ftell/ fclose,然后fopen再次用a+,但我认为这是可能做到这一点而无需打开和多次关闭文件.
我想在我的Java桌面应用程序上生成警报:
我正在使用Java,Eclipse,SWT进行开发,我的应用程序是使用Java Web Start从我的服务器部署的.我正在使用Mac OS X.6进行开发.
我想我有几个选择:
我真的不喜欢这个解决方案,我希望有更优雅的东西.
参考:我想在Mac OS/Windows上的System Startup上运行我的Java程序.我怎样才能做到这一点?
如果我将它作为系统服务运行,我可以从中受益,因为操作系统将确保我的软件:
我研究了一些我可以使用的资源:
我在系统服务选项中的问题是:
我的计划实施是否正确:
因此,在第一次运行时,应用程序将安装该服务并启动它.当应用程序关闭时,服务仍在运行,并且不再需要应用程序,除非它未注册.
但是,我想我仍然会错过"启动时运行"功能.
我对吗?我错过了什么吗?
在Unix上,我可以轻松使用cron表而无需应用程序将用户升级为root.我不需要处理重启,系统日期更改等.看起来不错.
在Windows上,我可以使用任务计划程序,即使在使用At或SchTasks的命令行中也是如此.这看起来不错,但是我需要这个兼容从XP到7,我不能轻易测试这个.
那你会怎么做?我错过了什么?您有什么建议可以帮助我选择最好,最优雅的解决方案吗?
我正在开发Android Studio/IntelliJ IDEA.
我已启用名为"常量条件和例外"的检查检查,如果我冒着NPE的风险,则显示警告,例如:
String foo = foo.bar(); // Foo#bar() is @nullable
if (foo.contains("bar")) { // I'm living dangerously
...
}
Run Code Online (Sandbox Code Playgroud)
我的代码中有以下内容:
String encoding = contentEncoding == null ? null : contentEncoding.getValue();
if (!TextUtils.isEmpty(encoding) && encoding.equalsIgnoreCase("gzip")) {
inputStream = new GZIPInputStream(entity.getContent());
} else {
inputStream = entity.getContent();
}
Run Code Online (Sandbox Code Playgroud)
这是源代码TextUtils#isEmpty(String):
/**
* Returns true if the string is null or 0-length.
* @param str the string to be examined
* @return true if str is null or zero length …Run Code Online (Sandbox Code Playgroud) android ×7
android-collapsingtoolbarlayout ×1
android-room ×1
back-stack ×1
c ×1
collections ×1
cron ×1
file-io ×1
gradle ×1
java ×1
listview ×1
service ×1
sqlite ×1