2016-06-30 20 views
1

このコードはOnCreate()関数にあります。このコードはオンラインで、バックグラウンドプロパティやその他のデザイン要素などをXMLファイルに変更する必要があります。どうすれば転送できるのか教えてください私のactivity_main.xmlファイルに何のエラーもありません(これは私が設計部分で作業します)。 ありがとうございます。このテキストをAndroid Studioのxmlファイルに追加するにはどうすればよいですか?

LinearLayout ll = new LinearLayout(this); 
    mRecordButton = new RecordButton(this); 
//RecordButton is a class I created and mRecordButton is an object which 
// inherits some porperties of it. 
//Same with PlayButton and mPlayButton 
    ll.addView(mRecordButton, 
      new LinearLayout.LayoutParams(
        ViewGroup.LayoutParams.WRAP_CONTENT, 
        ViewGroup.LayoutParams.WRAP_CONTENT, 
        0)); 
    mPlayButton = new PlayButton(this); 
    ll.addView(mPlayButton, 
      new LinearLayout.LayoutParams(
        ViewGroup.LayoutParams.WRAP_CONTENT, 
        ViewGroup.LayoutParams.WRAP_CONTENT, 
        0)); 
    setContentView(ll); 
} 

答えて

1

レイアウトは次のように:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 

    <com.yourcompany.package.RecordButton 
     android:id="@+id/record_btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
    <com.yourcompany.package.PlayButton 
     android:id="@+id/play_btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 

<LinearLayout/> 

次に、その同じのonCreate()メソッドでは、既存のコードを削除し、setContentView(R.layout.layout_name)

+0

ねえを使用します!入力いただきありがとうございます。 RecordButtonクラスとPlayButtonクラスはMainActivityで宣言されており、このステートメントはとして与えられていますが、それは私にレンダリングエラーを与え、クラスが見つかりませんでした。その理由は何でしょうか? – Sahil

+0

これらのクラスは公開されていますか?いずれにしても、これらのクラスを自分のファイルに入れることをお勧めします。 – FishStix

+0

私は別々のクラスで作成しました。しかし、新しいクラスIは次のようになります。public class RecordButton extends Button。これでViewを拡張する必要があります。私はpublic class RecordButton Buttonを継承していることを知っています。ビューは不可能です。私は何をすべきか提案できますか?あなたが同じことがインターフェイスや何かがすばらしいことができるかを知っているならば!ありがとう – Sahil

関連する問題