我是Android的新手并且遵循Udacity Android开发人员课程来学习.我在第3章,他们教你如何在你的应用程序中添加设置.我已经从android studio添加了SettingActivity.当我点击设置菜单时,我的应用程序崩溃了.这是我的pref_general.xml文件
<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="@string/pref_location_key"
android:defaultValue="@string/pref_location_default"
android:maxLines="1"
android:inputType="text"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/pref_location_label" />
Run Code Online (Sandbox Code Playgroud)
我在SettingActivity中进行了这些更改
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupActionBar();
addPreferencesFromResource(R.xml.pref_general);
bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_location_key)));}
Run Code Online (Sandbox Code Playgroud)
单击"设置"菜单时出现以下异常
Process: com.example.android.sunshine.app, PID: 10131
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.sunshine.app/com.example.android.sunshine.app.SettingsActivity}: java.lang.RuntimeException: Modern two-pane PreferenceActivity requires use of a PreferenceFragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.access$800(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343) …
Run Code Online (Sandbox Code Playgroud) 我想在android上传输一个rtsp流,我终于得出结论,我不能使用android API的MediaPlayer,Videoview等,因为延迟对我来说是个大问题.我需要一个<500毫秒的延迟.现在我打算使用Gstreamer或ffmpeg来创建一个android rtsp客户端.我只是有点疑惑
Gstreamer或ffmpeg客户端是否能够提供<500毫秒的延迟.我读到有些参数我可以通过调整来获得非常低的延迟.只是想确认一下.我有很好的网络带宽.帧大小通常为1920X1080.
我读过Gstreamer是一个比ffmpeg高一级并使用ffmpeg编解码器工作的.我想知道哪一个更容易用于创建一个Android客户端.在ffmpeg上直接使用Gstreamer或workig.
如果我使用Gstreamer android客户端,我是否还必须使用Gstreamer服务器来传输数据?目前我正在使用Live555 RTSP服务器来传输数据
我想使用freeglut创建opengGL上下文。我将首先通过使用glew和其他一些参数检查支持版本来确定要使用的上下文。我知道要让它正常工作,它需要一个opengl上下文。因此,我首先使用glutCreateWindow创建一个上下文,然后检查支持的版本,然后使用glutInitContextVersion()设置所需的版本,并使用glutDestroyWindow销毁先前的窗口,并使用glutCreateWindow重新创建新窗口。我收到此错误 Freeglut错误:错误:没有为窗口1注册任何显示回调(我检查了1是我销毁的上一个窗口的ID)。以下是我的代码
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(900, 600);
int winID = glutCreateWindow("Rotating Cube"); //winID is 1 here
glewExperimental = GL_TRUE;
glewInit();
//I decide the context on some other parameters also except the supported version reported by glew.
//I have tested this with opengl 3.2 core profile as well.
//This is not working even if I forcefully set the opengl version to 2.0
if (glewIsSupported("GL_VERSION_3_1"))
{
glutInitContextVersion (3, 1);
glutInitContextFlags (GLUT_FORWARD_COMPATIBLE);
//glutInitContextVersion (3, 2);
//glutInitContextFlags …
Run Code Online (Sandbox Code Playgroud) 我想更改RecyclerView项目的背景颜色.我想我应该能够在onBindViewHolder
方法中做到这一点, 但我无法做到这一点.我只更改了项目的底部边框颜色,但我想更改完整的背景颜色
这就是我想要的
public void onBindViewHolder(InstalledFontViewRecyclerAdapter.ViewHolder holder, int position) {
if (//Some Condition) {
holder.itemView.setBackgroundColor(Color.GREY);
}
else {
holder.itemView.setBackgroundColor(Color.RED);
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这应该产生类似的东西
我得到的就是这个
这是我的RecyclerView Fragment layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/installed_recyclerView"
android:paddingTop="1dp"
></android.support.v7.widget.RecyclerView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的项目布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="3dp"
android:paddingBottom="1dp"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/post_card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="1dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Arial New"
android:id="@+id/installed_font_name"
android:textSize="16dp"
/> …
Run Code Online (Sandbox Code Playgroud) 我正在使用 recyclerView 使用 asysnc 任务显示图像。我正在从 Web 服务器获取图像。我的代码是
从我调用的 onBindViewHolder 方法
new ImageLoadTask(url, holder.imageView).execute();
Run Code Online (Sandbox Code Playgroud)
我的 ImageLoader asysnc 任务是
public class ImageLoadTask extends AsyncTask<Void, Void, Bitmap> {
private String url;
private ImageView imageView;
ProgressDialog pDialog;
public ImageLoadTask(String url, ImageView imageView) {
this.url = url;
this.imageView = imageView;
}
@Override
protected Bitmap doInBackground(Void... params) {
try {
URL urlConnection = new URL(url);
HttpURLConnection connection = (HttpURLConnection) urlConnection
.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (Exception …
Run Code Online (Sandbox Code Playgroud) 我正在使用OpenGL,并且我正在使用的版本存在一些问题.当我检查我的版本时glGetString(GL_VERSION)
,我得到"4.2.0 - Build 10.18.10.3574".我有以下问题:
在一种方法中,我使用固定管道进行渲染,但我知道从OpenGL 3.1中删除了对固定管道的支持,那么我的代码如何与4.2一起工作?我使用的API一样glTranslatef()
,glMatrixMode(GL_PROJECTION)
.我认为这些都已弃用,仅适用于OpenGL 1.1.那么当我将上下文字符串作为OpenGL 4.2时,代码是如何工作的?我想我必须使用OpenGL 1.1,但为什么上下文版本是4.2?
当我使用着色器时,我使用以下代码创建3.1或更高版本的上下文.我使用的着色器是旧的着色器,它与OpenGL 2.0兼容,并且具有"属性","变化"等关键字,不应与OpenGL 3.1或更高版本一起使用.我应该将我的着色器更新为OpenGLSL 3.1,比如使用"in","out"等.还有一些不赞成的东西,比如GL_LINE_SMOOTH_HINT
,glMatrixMode(GL_PROJECTION)
.我认为这些东西已经从OpenGL 3.0中弃用了.那么这些东西如何与GL上下文3.1及更高版本一起使用?
创建上下文3.1或更高版本的代码
if ( 0 == (m_tempContext = ::wglCreateContext( m_pDC->GetSafeHdc() ) ) )
{
AfxMessageBox(_T("wglCreateContext failed."));
return FALSE;
}
if ( FALSE == ::wglMakeCurrent( m_pDC->GetSafeHdc(), m_tempContext ) )
{
AfxMessageBox(_T("wglMakeCurrent failed."));
return FALSE;
}
int attribs[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
WGL_CONTEXT_FLAGS_ARB, 0,
0
};
if(wglewIsSupported("WGL_ARB_create_context") == 1)
{
m_hRC = wglCreateContextAttribsARB(m_pDC->GetSafeHdc() ,0, attribs); …
Run Code Online (Sandbox Code Playgroud)