我已经实现了水平滚动RecyclerView
.我RecyclerView
使用了LinearLayoutManager
,而我面临的问题是,当我尝试使用scrollToPosition(position)
或smoothScrollToPosition(position)
或LinearLayoutManager
的scrollToPositionWithOffset(position)
.对我来说都不适用.滚动调用不会滚动到所需位置,也不会调用OnScrollListener
.
到目前为止,我已经尝试了很多不同的代码组合,我不能在这里发布它们.以下是对我有用的(但只是部分):
public void smoothUserScrollTo(final int position) {
if (position < 0 || position > getAdapter().getItemCount()) {
Log.e(TAG, "An attempt to scroll out of adapter size has been stopped.");
return;
}
if (getLayoutManager() == null) {
Log.e(TAG, "Cannot scroll to position a LayoutManager is not set. " +
"Call setLayoutManager with a non-null layout.");
return;
}
if (getChildAdapterPosition(getCenterView()) == position) {
return;
}
stopScroll(); …
Run Code Online (Sandbox Code Playgroud) 我有一个项目,我尝试在Android Studio中打开,但是当导入项目时,我收到一个错误
错误:原因:org/jetbrains/plugins/gradle/tooling/ModelBuilderService
我在谷歌上搜索,发现这是Windows上常见的问题.但是,所有提供的解决方案是:
.gradle
.Invalidate Cache/Restart
来自File
Android Studio.这是我在上面的列表中尝试过的内容.
C:/Users/<username>/.android<>
旧目录手动删除Android Studio设置.%temp%
文件夹.除了这个项目之外,这个项目适用于所有安装了Android Studio的电脑.
我retrofit2.0
在我的应用程序中使用simpleframework.xml
库.
问题是当我没有proguard运行应用程序时它工作正常但是当我运行proguard时我在日志中得到以下错误.
E/ERROR: java.lang.RuntimeException: org.simpleframework.xml.core.PersistenceException: Constructor not matched for class A
Run Code Online (Sandbox Code Playgroud)
A类没有/ default构造函数应该可以工作.我还添加了一个No Argument Constructor.但这并没有纠正这个问题.
类一
@Root(name = "data",strict = false)
public class A {
@Element(name = "baseurl",required = false)
private String baseURl;
@Element(name = "country_code")
private String country_code;
// Setters and getters
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,没有构造函数(添加默认的空构造函数可以解决问题).所以默认的No Argument Constructor应该也能正常工作.但是,我尝试使用以下构造函数,这将删除错误.
public A(@ELement(name = "baseurl") String baseUrl,
@Element(name = "country_code") String country_code) { // Add all the elements from the xml in the constructor i.e. …
Run Code Online (Sandbox Code Playgroud) android proguard xml-deserialization android-proguard simple-xml-converter
我正在使用批注处理,无法通过代码中的导入直接使用生成的文件。相反,我必须在生成的类之前添加完整的包。我发布了一个SO问题错误:程序包generate.schema不存在。
最后,我弄清楚了原因,结果很简单,请参阅同一篇文章的答案。原来错误是因为我在最后一轮处理中生成文件,而不是在两者之间的任何地方生成文件。
所以我的问题是:
与上一轮之间生成文件相比,在上一轮之间生成文件如何改变对代码中生成文件的访问?
是否有特定原因(与Java相关或其他原因)?
考虑以下功能:
int main()
{
//statement(s);
func1();
//statement(s);
}
void func1()
{
//statement(s);
func2();
//statement(s);
}
void func2()
{
//statement(s);
}
Run Code Online (Sandbox Code Playgroud)
在func2
完成所有操作后,编译器如何知道返回的位置?我知道,控制转移到功能func1
(以及到底哪个说法),但怎么也编译器知道吗?是什么告诉编译器返回哪里?
我是Android的新手,我有点困难了6个小时.
问题是我不知道首选项文件的名称,我需要从首选项文件中获取值.我正在使用Android Studio并创建了"设置活动".我没有给任何文件命名,除了SettingsActivity.java
.
所以我的问题是共享首选项文件的名称是什么(因为应用程序保留了值).否则,如果有办法找出答案.
或许我在代码中遗漏了一些明显的东西.以下是我的相关代码.
String key = "example_text";
final String PREF_FILE_NAME = "SettingsActivity";
SharedPreferences preferences = getSharedPreferences(PREF_FILE_NAME, MODE_PRIVATE);
String value = preferences.getString(key, " null");
Run Code Online (Sandbox Code Playgroud)
编辑1:我有一个名为的活动RemoteDevice.java
,在此活动中,我有一个用于互联网使用的异步任务子类.现在我通过上面提到的PreferencesActivity存储了IP地址,现在想要检索它.但我无法找到它.
编辑2:在下面的代码中,我试图从编辑文本中获取价值.
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<!-- NOTE: EditTextPreference accepts EditText attributes. -->
<!-- NOTE: EditTextPreference's summary should be set to its value by the activity code. -->
<EditTextPreference
android:key="example_text"
android:title="@string/pref_host_ip_address"
android:defaultValue="@string/pref_default_host_address"
android:selectAllOnFocus="true"
android:inputType="numberDecimal"
android:digits="123456789."
android:capitalize="words"
android:singleLine="true"
android:maxLines="1" />
<!-- NOTE: Hide buttons to simplify the UI. Users can touch outside …
Run Code Online (Sandbox Code Playgroud) android preferenceactivity android-preferences sharedpreferences
我的Android应用程序中有以下代码.
我的res/values/styles.xml:
<style name="FullScreen" parent="@style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
Run Code Online (Sandbox Code Playgroud)
RES /绘制/ background_splash.xml:
<item
android:drawable="@color/colorPrimaryDark"/>
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/image1"/>
</item>
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中:
<activity
android:name=".SplashActivity"
android:theme="@style/FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
SplashActivity.java:
public class SplashActivity extends AppCompatActivity {
private static int SPLASH_TIME_OUT = 5000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(SplashActivity.this, MainActivity.class);
startActivity(i);
finish();
}
}, SPLASH_TIME_OUT);
}
}
Run Code Online (Sandbox Code Playgroud)
我在res文件夹中存在具有适当分辨率/大小的image1.但是启动画面不会显示覆盖全屏的图像,而是仅在屏幕的某些部分显示缩小的尺寸.能否请您提出建议.我查看了一些网站上提出的一些建议,但没有帮助.