I am novice in android development. I am trying to align my page elements vertically, but unable to do that. I don't know, how I can use front-end layout control in Java.
My main.xml file is as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<!--<View-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="30dip"/>-->
<TextView
android:text="@string/getVerse"
android:layout_width="wrap_content"
android:layout_height="100dip"
android:textSize="@dimen/header"
android:layout_gravity="center_horizontal"
/>
<!--<View-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="20dip"-->
<!--/>-->
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="@dimen/questionSize"
android:hint="@string/questionHint"
/>
<!--<View-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="25dip"-->
<!--/>-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="@dimen/buttonTextSize"
android:text="@string/buttonText">
</Button>
</LinearLayout>
The page looks like:
Please help me!!!
Add following code to your parent LinearLayout
android:orientation="vertical"
To show Gif in Activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new GifView(this));
}
static class GifView extends View {
Movie movie;
GifView(Context context) {
super(context);
File myFile = new File("/sdcard/test.gif");
InputStream fis = null;
try {
fis = new BufferedInputStream(new FileInputStream(myFile),
16 * 1024);
fis.mark(16 * 1024);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
movie = Movie.decodeStream(fis);
Log.e("SS", "movie.duration()" + movie.duration());
}
@Override
protected void onDraw(Canvas canvas) {
try {
if (movie != null) {
movie.setTime((int) SystemClock.uptimeMillis()
% movie.duration());
movie.draw(canvas, 0, 0);
invalidate();
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
Just use android:orientation="vertical"
attribute in your LinearLayout
. You are getting the elements aligned Horizontally
as this is the default provided by android.
The code after doing so is shown below :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<!--<View-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="30dip"/>-->
<TextView
android:text="@string/getVerse"
android:layout_width="wrap_content"
android:layout_height="100dip"
android:textSize="@dimen/header"
android:layout_gravity="center_horizontal"
/>
<!--<View-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="20dip"-->
<!--/>-->
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="@dimen/questionSize"
android:hint="@string/questionHint"
/>
<!--<View-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="25dip"-->
<!--/>-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="@dimen/buttonTextSize"
android:text="@string/buttonText">
</Button>
</LinearLayout>
Hope this Helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With