Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid : Make buttons appear at bottom of screen
    primarykey
    data
    text
    <p>I have a class to record audio notes i wish to implement this into an existing activity, however the record and play buttons in this instance, end up at the top of the screen and mess things up.</p> <p>Where and how can I specify the display properties of the button's using the following code...</p> <p><strong>JAVA</strong> - AudioRecordTest.java</p> <pre><code>public class AudioRecordTest extends Activity { private static final String LOG_TAG = "AudioRecordTest"; private static String mFileName = null; private RecordButton mRecordButton = null; private MediaRecorder mRecorder = null; private PlayButton mPlayButton = null; private MediaPlayer mPlayer = null; private void onRecord(boolean start) { if (start) { startRecording(); } else { stopRecording(); } } private void onPlay(boolean start) { if (start) { startPlaying(); } else { stopPlaying(); } } private void startPlaying() { mPlayer = new MediaPlayer(); try { mPlayer.setDataSource(mFileName); mPlayer.prepare(); mPlayer.start(); } catch (IOException e) { Log.e(LOG_TAG, "prepare() failed"); } } private void stopPlaying() { mPlayer.release(); mPlayer = null; } private void startRecording() { mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mRecorder.setOutputFile(mFileName); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); try { mRecorder.prepare(); } catch (IOException e) { Log.e(LOG_TAG, "prepare() failed"); } mRecorder.start(); } private void stopRecording() { mRecorder.stop(); mRecorder.release(); mRecorder = null; } class RecordButton extends Button { boolean mStartRecording = true; OnClickListener clicker = new OnClickListener() { public void onClick(View v) { onRecord(mStartRecording); if (mStartRecording) { setText("Stop recording"); } else { setText("Start recording"); } mStartRecording = !mStartRecording; } }; public RecordButton(Context ctx) { super(ctx); setText("Start recording"); setOnClickListener(clicker); } } class PlayButton extends Button { boolean mStartPlaying = true; OnClickListener clicker = new OnClickListener() { public void onClick(View v) { onPlay(mStartPlaying); if (mStartPlaying) { setText("Stop playing"); } else { setText("Start playing"); } mStartPlaying = !mStartPlaying; } }; public PlayButton(Context ctx) { super(ctx); setText("Start playing"); setOnClickListener(clicker); } } public AudioRecordTest() { mFileName = Environment.getExternalStorageDirectory().getAbsolutePath(); mFileName += "/audiorecordtest.3gp"; } @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mRecordButton = new RecordButton(this); mPlayButton = new PlayButton(this); setContentView(R.layout.activity_audio_record_test); } @Override public void onPause() { super.onPause(); if (mRecorder != null) { mRecorder.release(); mRecorder = null; } if (mPlayer != null) { mPlayer.release(); mPlayer = null; } } } </code></pre> <p><strong>XML</strong> - activity_audio_record_test.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;ScrollView android:layout_height="fill_parent" android:layout_width="fill_parent" &gt; &lt;LinearLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical"&gt; &gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Inspection ID" /&gt; &lt;EditText android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/txtName" android:inputType="number" android:maxLength="5" android:digits="0123456789" android:singleLine="true" /&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Text1" /&gt; &lt;EditText android:id="@+id/txt1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:autoText="false" android:gravity="top|left" android:lines="4" android:maxLines="4" android:minLines="4" android:scrollbars="vertical" android:singleLine="false" android:width="0dip" /&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Project Ref" /&gt; &lt;EditText android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/txtAge" android:inputType="number" android:maxLength="5" android:digits="0123456789" android:singleLine="true" /&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Drop Down" /&gt; &lt;Spinner android:id="@+id/spinDept" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;Button android:id="@+id/btnPhotoCamera" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Take Image with Camera" /&gt; &lt;Button android:id="@+id/btnPhotoGallery" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Get Image from Gallery" /&gt; &lt;TextView android:id="@+id/lblDisplayImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/btnCancel" android:layout_centerHorizontal="true" android:layout_marginTop="10dp" android:text="below_this_text_image_will_be_displayed" android:textSize="13dp" /&gt; &lt;RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_below="@+id/lblDisplayImage" android:layout_centerInParent="true" android:layout_marginTop="10dp" android:gravity="bottom" &gt; &lt;!-- &lt;ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" &gt; --&gt; &lt;ImageView android:id="@+id/imgDisplayImage" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:contentDescription="area_where_image_is_to_be_displayed" /&gt; &lt;!-- &lt;/ScrollView&gt; --&gt; &lt;/RelativeLayout&gt; &lt;------------------- RECORD AND PLAY BUTTONS TO GO HERE -------------&gt; &lt;Button android:id="@+id/btnAdd" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="btnAddEmp_Click" android:text="Save Inspection" /&gt; &lt;Button android:id="@+id/btnCancel" android:layout_width="120dp" android:layout_height="wrap_content" android:layout_below="@+id/btnPhotoGallery" android:layout_centerHorizontal="true" android:layout_marginTop="19dp" android:text="Reset/Clear Form Data" /&gt; &lt;TextView android:id="@+id/txtEmps" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Number of Inspections on Device " /&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; &lt;/LinearLayout&gt; </code></pre> <p>Thanks,</p> <p>henry</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload