我有多个LinearLayouts,其组合高度很容易超过设备的屏幕高度.所以为了使我的布局可滚动,我尝试添加一个ScrollView,但不幸的是我收到以下错误:
Scrollview只能容纳一个直接孩子
我做了一些研究,但即使在阅读了几个解决方案之后,也无法理解如何解决它.我尝试了一些改变,但到目前为止我没有任何作用.有帮助吗?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20dip">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 1"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="@+id/q1_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 2"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="@+id/q2_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Question 3"
android:paddingBottom="20dip"
android:gravity="center" />
<TextView
android:id="@+id/q3_score"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:gravity="center"/>
</LinearLayout> …Run Code Online (Sandbox Code Playgroud) 收到电话时,MediaPlayer不会暂停.如果有人能提供帮助就会很棒!
码:
public class player1 extends Activity implements Runnable {
private MediaPlayer mp;
private ProgressBar progressBar;
private ImageButton pauseicon;
private final int NUM_SOUND_FILES = 3; //*****REPLACE THIS WITH THE ACTUAL NUMBER OF SOUND FILES YOU HAVE*****
private int mfile[] = new int[NUM_SOUND_FILES];
private Random rnd = new Random();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player_1);
pauseicon = (ImageButton) findViewById(R.id.pauseicon);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
getActionBar().setDisplayHomeAsUpEnabled(true);
mfile[0] = R.raw.sound01; //****REPLACE THESE WITH THE PROPER NAMES OF YOUR SOUND FILES
mfile[1] = …Run Code Online (Sandbox Code Playgroud) 我正试图在我的应用程序中使用标记在片段中设置Google地图.当我第一次点击它时它起作用,但是当我点击另一个片段然后返回谷歌地图时它会崩溃.不确定是什么问题?任何帮助都会很棒,只有初学者.
继承人代码:
XML
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
Run Code Online (Sandbox Code Playgroud)
Java google maps片段编辑工作代码如下
public class Fragment_8 extends Fragment{
static final LatLng BottleCapp = new LatLng(51.371986, 0.065593);
private GoogleMap map;
private static View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (view != null) {
ViewGroup parent = (ViewGroup) view.getParent();
if (parent != null)
parent.removeView(view);
}
try {
view = inflater.inflate(R.layout.fragment_8, container, false);
} catch (InflateException e) {
/* map is already there, just return …Run Code Online (Sandbox Code Playgroud) android google-maps android-fragments google-maps-android-api-2
从网站制作应用和流媒体音频.我有一个菜单,当我点击按钮打开收音机活动时,它可能需要8-20秒才能加载,有时会强制关闭.任何帮助都会非常棒,谢谢.
码:
public class Radio extends Activity {
private MediaPlayer mp;
private ImageButton pauseicon;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player_1);
pauseicon = (ImageButton) findViewById(R.id.pauseicon);
getActionBar().setDisplayHomeAsUpEnabled(true);
/**
* Play button click event plays a song and changes button to pause
* image pauses a song and changes button to play image
* */
String res = "http://216.235.91.36/play?s=magic24point7&d=LIVE365&r=0&membername=&session=magic24point7:0&AuthType=NORMAL&app_id=live365%3ABROWSER&SaneID=24.79.96.172-13316781890137014897763&tag=live365";
mp = new MediaPlayer();
try {
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setDataSource(res);
mp.prepare();
mp.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace(); …Run Code Online (Sandbox Code Playgroud) WebView没有正确显示网站.任何帮助都会很棒!代码已经在所有其他网站上使用了.不确定这个问题是什么.我应该添加什么?适用于Chrome和其他浏览器,因此不知道该怎么做.任何帮助都会很棒!
的WebView

铬

public class Website extends Activity {
WebView myWebView;
LinearLayout root;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.website);
myWebView = (WebView) findViewById(R.id.webView);
root = (LinearLayout) findViewById(R.id.root);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.addJavascriptInterface(new WebAppInterface(this), "Android");
myWebView.setWebViewClient(new WebViewClient());
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.getSettings().setSupportZoom(true);
myWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
myWebView.getSettings().setDomStorageEnabled(true);
myWebView.loadUrl("http://dspart.org/");
getActionBar().setDisplayHomeAsUpEnabled(true);
}
public class WebAppInterface {
Context mContext;
/** Instantiate the interface and set the context */
WebAppInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
@JavascriptInterface
public …Run Code Online (Sandbox Code Playgroud) 得到错误,抱歉只是初学者.所有的帮助都会很棒.
05-31 21:49:16.077: E/AndroidRuntime(655): FATAL EXCEPTION: main
05-31 21:49:16.077: E/AndroidRuntime(655): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.appal.song/com.appal.song.MainActivity}: java.lang.NullPointerException
05-31 21:49:16.077: E/AndroidRuntime(655): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-31 21:49:16.077: E/AndroidRuntime(655): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-31 21:49:16.077: E/AndroidRuntime(655): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-31 21:49:16.077: E/AndroidRuntime(655): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-31 21:49:16.077: E/AndroidRuntime(655): at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 21:49:16.077: E/AndroidRuntime(655): at android.os.Looper.loop(Looper.java:137)
05-31 21:49:16.077: E/AndroidRuntime(655): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-31 21:49:16.077: E/AndroidRuntime(655): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 21:49:16.077: E/AndroidRuntime(655): at java.lang.reflect.Method.invoke(Method.java:511)
05-31 21:49:16.077: E/AndroidRuntime(655): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-31 21:49:16.077: E/AndroidRuntime(655): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-31 21:49:16.077: E/AndroidRuntime(655): at dalvik.system.NativeStart.main(Native Method)
05-31 …Run Code Online (Sandbox Code Playgroud)