我有一个应用程序,我需要适应Android TV.此应用程序包含水平RecyclerView,当我按遥控器上的D-pad按钮时它不会滚动.我找到了这个解决方案,但它崩溃了.这是代码:
<ru.myapp.package.HorizontalPersistentFocusWrapper
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="@null"
android:scrollbars="none"/>
</ru.myapp.package.HorizontalPersistentFocusWrapper>
Run Code Online (Sandbox Code Playgroud)
HorizontalPersistentFocusWrapper与PersistentFocusWrapper相同,但mPersistFocusVertical = false;
在这个地方发生崩溃:
@Override
public void requestChildFocus(View child, View focused) {
super.requestChildFocus(child, focused);
View view = focused;
while (view != null && view.getParent() != child) {
view = (View) view.getParent(); <<<------ Crash here
}
mSelectedPosition = view == null ? -1 : ((ViewGroup) child).indexOfChild(view);
if (DEBUG) Log.v(TAG, "requestChildFocus focused " + focused + " mSelectedPosition " + mSelectedPosition);
}
Run Code Online (Sandbox Code Playgroud)
崩溃堆栈跟踪:
java.lang.ClassCastException: android.view.ViewRootImpl cannot …Run Code Online (Sandbox Code Playgroud) 我正在使用ConstraintLayout进行活动:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.site.path.to.AuthenticationActivity">
<EditText
android:id="@+id/login"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="none"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<EditText
android:id="@+id/password"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="textPassword"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/login"/>
<Button
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Log in"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/password"/>
<FrameLayout
android:visibility="gone"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/default_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
</FrameLayout>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
FrameLayout应该在可见时隐藏页面的所有内容。但是它隐藏了除按钮以外的所有内容。为什么按钮没有隐藏?如何解决?
我正在尝试使用此代码来解析带有时区的日期字符串进行测试:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZZZZZ", Locale.US);
Calendar calendar = Calendar.getInstance();
calendar.setTime(sdf.parse("2017-07-26T06:00-06:00"));
int offset = calendar.getTimeZone().getRawOffset();
Run Code Online (Sandbox Code Playgroud)
我正在尝试将时区从 更改-06为+09,但offset始终包含10800000.
如何正确解析带有时区的日期(我需要时间和时区)?
在我的FreeBSD 10.0服务器上,我收到以下错误:
# make
/usr/bin/g++ crypto.cpp md4.cpp rsalib1.cpp base64.cpp cmdbase.cpp signer.cpp wmsigner.cpp -o wmsigner
make: exec(/usr/bin/g++) failed (No such file or directory)
*** Error code 1
Stop.
make: stopped in /tmp/wmsigner-2.0.3
Run Code Online (Sandbox Code Playgroud)
/usr/bin/g++ 不存在,我该如何安装/修复此问题?
我在我的应用程序中创建并使用自定义RecyclerView.我需要getChildAt(0).getWidth()在任何工作之前调用以保存类字段中的第一个项目宽度.为此我需要在适配器中加载数据时捕获(否则getChildAt(0)将返回null).
如何在自定义RecyclerView中捕获数据加载事件?
我使用以下代码将目录路径保存到注册表:
HKEY hKey;
RegCreateKeyEx(HKEY_CURRENT_USER, L"Software\\BArtWell\\MyApp", 0, NULL, REG_OPTION_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
RegSetValueEx(hKey,L"Directory",0,REG_SZ,(LPBYTE)sz,(DWORD)wcslen(sz)*sizeof(wchar_t));
RegCloseKey(hKey);
Run Code Online (Sandbox Code Playgroud)
它在重新启动之前工作正常。但重启后路径 HKCU\Software\BArtWell\MyApp 不存在。在 XP 和 Windows7 上测试,结果相同。我做错了什么?
我用这段代码下载图像:
ImageGetter imageGetter = new ImageGetter() {
@Override
public Drawable getDrawable(String source) {
Drawable drawable = null;
try {
URL url = new URL(source);
String path = Environment.getExternalStorageDirectory().getPath()+"/Android/data/com.my.pkg/"+url.getFile();
File f=new File(path);
if(!f.exists()) {
URLConnection connection = url.openConnection();
InputStream is = connection.getInputStream();
f=new File(f.getParent());
f.mkdirs();
FileOutputStream os = new FileOutputStream(path);
byte[] buffer = new byte[4096];
int length;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
os.close();
is.close();
}
drawable = Drawable.createFromPath(path);
} catch (MalformedURLException e) {
e.printStackTrace();
} …Run Code Online (Sandbox Code Playgroud) 我需要在2D数组中获得第二级的大小.我正在尝试这个:
my @txt;
$txt[0][0]="text1";
$txt[0][1]="text2";
$txt[0][2]="text3";
$txt[1][0]="text4";
$txt[1][1]="text5";
$txt[1][2]="text6";
print scalar(@txt[1]);
Run Code Online (Sandbox Code Playgroud)
但它不起作用,我看到"ARRAY(0x804daf0)".如何获得第二维的大小?
我在我的应用程序中使用Picasso 2.5.2.它运行良好,但无法从第三方服务器之一加载图片.当我尝试从此站点加载图片时,我收到此错误:
java.net.UnknownServiceException: CLEARTEXT communication not enabled for client
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:98)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:196)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:132)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:101)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179)
at okhttp3.RealCall.execute(RealCall.java:63)
at com.jakewharton.picasso.OkHttp3Downloader.load(OkHttp3Downloader.java:136)
at com.squareup.picasso.NetworkRequestHandler.load(NetworkRequestHandler.java:47)
at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:206)
at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:411)
Run Code Online (Sandbox Code Playgroud)
当我在浏览器中打开此图像时,它会成功加载.网址看起来像http://somesite.com/path/to/file/123456.jpg.是毕加索的虫子吗?怎么解决?
我需要在 TextView 中显示 SmallCaps 文本。我正在尝试使用以下代码:
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFeatureSettings="smcp"
android:textColor="@color/black"
android:textSize="16sp"
android:text="TEXT" />
Run Code Online (Sandbox Code Playgroud)
但它只显示普通文本,没有 SmallCaps 效果。我也尝试以编程方式设置它 ( text1.fontFeatureSettings = "smcp") 但也没有成功。
如何在 Android 中制作 SmallCaps 文本?为什么 fontFeatureSettings 不起作用?