###前提・実現したいこと
androidアプリで縦にスクロールする機能をつけたいです。
res/layout/sample
この場所にxmlを作成しています。
###発生している問題・エラーメッセージ
LenarLayoutとButtonは追加できるのですがSclollViewを追加するとエラーになってしまいました。
Error:(16, 31) No resource found that matches the given name (at 'text' with value '@string/click').
###該当のソースコード
java
1<?xml version="1.0" encoding="utf-8"?> 2<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 <ScrollView 6 android:layout_width="match_parent" 7 android:layout_height="match_parent" 8 android:id="@+id/scroll" 9 <LinearLayout 10 android:layout_width="match_parent" 11 android:layout_height="match_parent" 12 android:orientation="vertical" 13 <Button 14 android:layout_width="match_parent" 15 android:layout_height="match_parent" 16 android:text="@string/click" 17 android:id="@+id/button"/> 18 </LinearLayout> 19 </ScrollView> 20</RelativeLayout> 21 22 23package net.yytto.scrolltest; 24import android.app.Activity; 25import android.os.Bundle; 26import android.view.View; 27import android.view.Window; 28import android.widget.Button; 29import android.widget.LinearLayout; 30import android.widget.ScrollView; 31import android.widget.Toast; 32 33//XMLによるレイアウト作成 34public class ScrollTest extends Activity 35 implements View.OnClickListener { 36 private Button button; 37 private LinearLayout linear; 38 private ScrollView scroll; 39 40 //アクティビティ起動時に呼ばれる 41 public void onCreate(Bundle bundle) { 42 super.onCreate(bundle); 43 requestWindowFeature(Window.FEATURE_NO_TITLE); 44 45 //レイアウトの指定 46 setContentView(R.layout.sample); 47 48 //コンポーネントの関連づけ 49 scroll = (ScrollView)this.findViewById(R.id.scroll); 50 linear = (LinearLayout)this.findViewById(R.id.linear); 51 button = (Button)this.findViewById(R.id.button); 52 button.setOnClickListener(this); 53 } 54 55 //ボタンクリック時に呼ばれる 56 public void onClick(View view) { 57 //ボタンを押したときの処理 58 if (view == button) { 59 toast("ボタンを押した"); 60 } 61 } 62 63 //トーストの表示 64 private void toast(String text) { 65 if (text == null) text = ""; 66 Toast.makeText(this, text, Toast.LENGTH_LONG).show(); 67 } 68}
###試したこと
元々書いてあるxmlns:androidを追加してみました
###補足情報(言語/FW/ツール等のバージョンなど)
Android Plugin Version 2.1.2
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/29 05:00
2016/06/29 05:10
2016/06/29 05:19