I implemented my own dialog.This is the xml- code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.MainActivity"
android:gravity="center_vertical|center_horizontal"
android:background="#00ffffff">
<LinearLayout
android:orientation="vertical"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="#ad1457"
android:gravity="center"
android:layout_above="#+id/gameOptions_difficulty"
android:layout_alignLeft="#+id/gameOptions_difficulty"
android:layout_alignStart="#+id/gameOptions_difficulty"
android:id="#+id/gameOptions_title"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gamemode_title"
android:layout_gravity="center_horizontal"
android:textColor="#efebe9"
android:textSize="10pt"
android:padding="10dp"
android:layout_marginBottom="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="#ad1457"
android:id="#+id/gameOptions_difficulty"
android:layout_above="#+id/gameOptions_gameMode"
android:layout_alignLeft="#+id/gameOptions_gameMode"
android:layout_alignStart="#+id/gameOptions_gameMode"
android:baselineAligned="false"
android:minHeight="50dp"
android:padding="5dp"
android:gravity="center_horizontal"
android:weightSum="1">
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="Easy"
android:id="#+id/easy_button"
android:layout_marginLeft="8dp"
android:onClick="setDifficulty" />
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="Medium"
android:id="#+id/medium_button"
android:onClick="setDifficulty" />
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="Hard"
android:id="#+id/hard_button"
android:onClick="setDifficulty" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="169dp"
android:orientation="vertical"
android:gravity="center"
android:background="#ad1457"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="#+id/gameOptions_gameMode"
android:weightSum="3">
<Button
android:id="#+id/roundbased_button"
android:layout_width="200dp"
android:layout_height="50dp"
android:onClick="setGameMode"
android:text="#string/roundbased_game_text" />
<Button
android:layout_width="200dp"
android:layout_height="50dp"
android:text="#string/to_the_end_text"
android:onClick="setGameMode"
android:id="#+id/toTheEnd_button"
android:layout_gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="#ad1457"
android:layout_below="#+id/gameOptions_gameMode"
android:layout_alignLeft="#+id/gameOptions_gameMode"
android:layout_alignStart="#+id/gameOptions_gameMode"
android:id="#+id/gameOptions_footer">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/back_button_text"
android:id="#+id/back_button"
android:layout_weight="1"
android:onClick="clickExitButton" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ok_button_text"
android:id="#+id/ok_button"
android:layout_weight="1"
android:onClick="clickOkButton" />
</LinearLayout>
</RelativeLayout>
Here is how i create the dialog :
gameOptions = new Dialog(MainActivity.this);
gameOptions.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
gameOptions.setContentView(R.layout.dialog_gameoptions);
gameOptions.show();
In the gui builder from android studio , my layout looks like this :
But when i launch my app on my phone(htc one m9) , the layout looks like this :
How do i have to change my layout, that it looks like the one in the gui builder?What am i missing?Thanks!.
If you use the Relativelayout you can avoid all of this Linearlayout.
For example this is one of the my Dialog
<RelativeLayout 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="com.ddz.diarioscolastico.Dialog_add_voto">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Inserire il voto"
android:id="#+id/textView4"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/voto_inserito"
android:layout_below="#+id/textView4"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:id="#+id/data_voto"
android:layout_below="#+id/voto_inserito"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Tipo di voto"
android:id="#+id/textView6"
android:layout_below="#+id/data_voto"
android:layout_centerHorizontal="true" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spinner_tipo_voto"
android:layout_below="#+id/textView6"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aggiungi"
android:id="#+id/button_aggiungi"
android:layout_below="#+id/spinner_tipo_voto"
android:layout_centerHorizontal="true" />
</RelativeLayout>
It's good in the phone and in the tablet too!
This is a simple activity that in the Manifest have this setting:
<activity
android:name=".Dialog_add_voto"
android:label="#string/title_activity_dialog_add_voto"
android:theme="#android:style/Theme.Holo.Light.Dialog" >
</activity>
But for your layout i suggest something like that after try to use only the Relativelayout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.MainActivity"
android:gravity="center_vertical|center_horizontal"
android:background="#00ffffff">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ad1457"
android:gravity="center"
android:layout_above="#+id/gameOptions_difficulty"
android:layout_alignLeft="#+id/gameOptions_difficulty"
android:layout_alignStart="#+id/gameOptions_difficulty"
android:id="#+id/gameOptions_title"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gamemode_title"
android:layout_gravity="center_horizontal"
android:textColor="#efebe9"
android:textSize="10pt"
android:padding="10dp"
android:layout_marginBottom="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ad1457"
android:id="#+id/gameOptions_difficulty"
android:layout_above="#+id/gameOptions_gameMode"
android:layout_alignLeft="#+id/gameOptions_gameMode"
android:layout_alignStart="#+id/gameOptions_gameMode"
android:baselineAligned="false"
android:minHeight="50dp"
android:padding="5dp"
android:gravity="center_horizontal"
android:weightSum="1">
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="Easy"
android:id="#+id/easy_button"
android:layout_marginLeft="8dp"
android:onClick="setDifficulty" />
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="Medium"
android:id="#+id/medium_button"
android:onClick="setDifficulty" />
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="Hard"
android:id="#+id/hard_button"
android:onClick="setDifficulty" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_contentt"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:background="#ad1457"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="#+id/gameOptions_gameMode"
android:weightSum="3">
<Button
android:id="#+id/roundbased_button"
android:layout_width="200dp"
android:layout_height="50dp"
android:onClick="setGameMode"
android:text="#string/roundbased_game_text" />
<Button
android:layout_width="200dp"
android:layout_height="50dp"
android:text="#string/to_the_end_text"
android:onClick="setGameMode"
android:id="#+id/toTheEnd_button"
android:layout_gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ad1457"
android:layout_below="#+id/gameOptions_gameMode"
android:layout_alignLeft="#+id/gameOptions_gameMode"
android:layout_alignStart="#+id/gameOptions_gameMode"
android:id="#+id/gameOptions_footer">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/back_button_text"
android:id="#+id/back_button"
android:layout_weight="1"
android:onClick="clickExitButton" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ok_button_text"
android:id="#+id/ok_button"
android:layout_weight="1"
android:onClick="clickOkButton" />
</LinearLayout>
</RelativeLayout>
That could be due to your Dialog size, which means, you have created a lot of LinearLayouts - RelativeLayouts with eachother.
Of course, that should not work!
Use ScrollView if these items are big or you may want to take a look at this tutorial:
http://developer.android.com/guide/practices/screens_support.html
and of course, do not trust Android Studio Preview all the time :)
Related
I have activity based of vertical LinearLayout
Something like that:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.idatt.activities.TitleBarFragment"
android:id="#+id/fr_title_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
tools:layout="#layout/title_bar_fragment" />
<ImageView
android:background="#drawable/img_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:contentDescription="Company logo" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="100dp"
android:paddingRight="0dp"
android:paddingStart="100dp"
android:paddingEnd="0dp">
<TextView style="#style/MyTextViewLabel"
android:text="#string/str_under_logo" />
<TextView android:id="#+id/tv_applicationVersion"
style="#style/MyTextViewLabel.Black.Data"
android:textColor="#color/blue_end"
android:textStyle="bold"
android:text="Version" />
</LinearLayout>
<TextView
style="#style/MyTextViewLabel"
android:paddingTop="10dp"
android:text="Ditat Mobile Dispatch is designed for asset-light motor carriers that use independent contractors/owner operators for their power solution"
android:layout_gravity="center"
android:paddingBottom="20dp"
android:textSize="14sp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#color/blue_end"
android:padding="5dp">
<TextView style="#style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="Serial Number"
android:textColor="#color/white"/>
<TextView android:id="#+id/tv_serial_number"
style="#style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="123456789012345"
android:textSize="22sp"
android:textColor="#28cdfb"/>
</LinearLayout>
<Button
android:id="#+id/bt_openSourceLicenses"
android:text="Open source licenses"
android:background="#color/transparent"
android:textColor="#color/blue_end"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
I want to place image as background but it needs to go into right bottom corner. How do I do that?
EDIT:
I tried to do it like this, by wrapping into FrameLayout and setting gravity for image but it doesn't put image to the bottom and I still need to know how to align it to the right
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/img_background"
android:layout_gravity="bottom"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.idatt.activities.TitleBarFragment"
android:id="#+id/fr_title_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
tools:layout="#layout/title_bar_fragment" />
<ImageView
android:background="#drawable/img_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:contentDescription="Company logo" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="100dp"
android:paddingRight="0dp"
android:paddingStart="100dp"
android:paddingEnd="0dp">
<TextView style="#style/MyTextViewLabel"
android:text="#string/str_under_logo" />
<TextView android:id="#+id/tv_applicationVersion"
style="#style/MyTextViewLabel.Black.Data"
android:textColor="#color/blue_end"
android:textStyle="bold"
android:text="Version" />
</LinearLayout>
<TextView
style="#style/MyTextViewLabel"
android:paddingTop="10dp"
android:text="Ditat Mobile Dispatch is designed for asset-light motor carriers that use independent contractors/owner operators for their power solution"
android:layout_gravity="center"
android:paddingBottom="20dp"
android:textSize="14sp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#color/blue_end"
android:padding="5dp">
<TextView style="#style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="Serial Number"
android:textColor="#color/white"/>
<TextView android:id="#+id/tv_serial_number"
style="#style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="123456789012345"
android:textSize="22sp"
android:textColor="#28cdfb"/>
</LinearLayout>
<Button
android:id="#+id/bt_openSourceLicenses"
android:text="Open source licenses"
android:background="#color/transparent"
android:textColor="#color/blue_end"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
I suggest you to wrap it into RelativeLayout.
Then in your ImageView tag add android:layout_alignParentBottom="true" and android:layout_alignParentRight="true" to align it at the bottom right corner.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/img_background"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.idatt.activities.TitleBarFragment"
android:id="#+id/fr_title_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
tools:layout="#layout/title_bar_fragment" />
<ImageView
android:background="#drawable/img_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:contentDescription="Company logo" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="100dp"
android:paddingRight="0dp"
android:paddingStart="100dp"
android:paddingEnd="0dp">
<TextView style="#style/MyTextViewLabel"
android:text="#string/str_under_logo" />
<TextView android:id="#+id/tv_applicationVersion"
style="#style/MyTextViewLabel.Black.Data"
android:textColor="#color/blue_end"
android:textStyle="bold"
android:text="Version" />
</LinearLayout>
<TextView
style="#style/MyTextViewLabel"
android:paddingTop="10dp"
android:text="Ditat Mobile Dispatch is designed for asset-light motor carriers that use independent contractors/owner operators for their power solution"
android:layout_gravity="center"
android:paddingBottom="20dp"
android:textSize="14sp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#color/blue_end"
android:padding="5dp">
<TextView style="#style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="Serial Number"
android:textColor="#color/white"/>
<TextView android:id="#+id/tv_serial_number"
style="#style/MyTextViewLabel"
android:layout_gravity="center_horizontal"
android:text="123456789012345"
android:textSize="22sp"
android:textColor="#28cdfb"/>
</LinearLayout>
<Button
android:id="#+id/bt_openSourceLicenses"
android:text="Open source licenses"
android:background="#color/transparent"
android:textColor="#color/blue_end"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="90dip"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<TextView
android:id="#+id/rowcontact_txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:text="Usama Sadiq"
android:textColor="#3a3838"
android:textSize="15dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/rowcontact_imgLocationIcon"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_below="#+id/rowcontact_txtName"
android:layout_marginLeft="10dip" />
<TextView
android:id="#+id/rowcontact_txtLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rowcontact_txtName"
android:layout_toRightOf="#+id/rowcontact_imgLocationIcon"
android:text="Dubai"
android:textColor="#898788"
android:textSize="11.5dp" />
<ImageView
android:id="#+id/rowcontact_imgIcon"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignBottom="#+id/rowcontact_txtLocation"
android:layout_marginLeft="94dp"
android:layout_toRightOf="#+id/rowcontact_txtName" />
</RelativeLayout>
</RelativeLayout>
i am trying to create layout for list-view item but i am not able to fix position of image and text with three different Position please tell me solution how to fix it. i have to create listviow item i am able to display list-view but like given screen
i have all icon an all but am unable to fix potion of text-view and image view like given screen
<LinearLayout 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" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="2"
android:layout_margin="5dp"
>
<TextView
android:id="#+id/rowcontact_txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Usama Sadiq"
android:textColor="#3a3838"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="#+id/rowcontact_txtLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rowcontact_txtName"
android:layout_toRightOf="#+id/rowcontact_imgLocationIcon"
android:text="Dubai"
android:textColor="#898788"
android:textSize="11.5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I have been editing my relativelayout all day, but I cannot produce a screen that is desirable.
Currently it looks like this :
It is not centered and there is a very awkward space between the hour time and the minutes time.
I am trying to figure out how to fix it so it is centered similar to this app except I include the little h and m.
I have done a lot of research and used almost every positioning view in Relative Layout, but still cannot produce it.
Properly aligning TextViews in RelativeLayout
This is my xml file. Not sure what to do I feel like I have exhausted all my options.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:seekarc="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/seekArcContainer"
android:layout_width="350dp"
android:layout_height="wrap_content"
>
</FrameLayout>
<include
layout="#layout/controls"
android:id="#+id/controls" />
<com.triggertrap.seekarc.SeekArc
android:id="#+id/seekArc"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_gravity="center_horizontal|bottom"
seekarc:thumb="#drawable/custom_seek_arc_control_selector"
android:padding="30dp"
seekarc:rotation="0"
seekarc:startAngle="0"
seekarc:sweepAngle="360"
seekarc:touchInside="true"
seekarc:arcColor="#30ff5b56"
seekarc:progressColor="#ffff3a35"
android:layout_below="#+id/seekArcContainer"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/hour_progress_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#color/red_highlight"
android:text="00"
android:textSize="90sp"
android:layout_toStartOf="#+id/little_hour_text2"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/minute_progress_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#color/red_highlight"
android:text="00"
android:textSize="90sp"
android:layout_toStartOf="#+id/little_minute_text2"
android:layout_alignTop="#+id/hour_progress_number"
android:layout_toLeftOf="#+id/little_minute_text2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="H"
android:textSize="24sp"
android:id="#+id/little_hour_text2"
android:textColor="#color/red_highlight"
android:layout_toStartOf="#+id/minute_progress_number"
android:layout_marginRight="45dp"
android:layout_alignBottom="#+id/hour_progress_number"
android:layout_toLeftOf="#+id/minute_progress_number" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="M"
android:textSize="24sp"
android:id="#+id/little_minute_text2"
android:textColor="#color/red_highlight"
android:layout_marginRight="36dp"
android:layout_alignRight="#+id/seekArc"
android:layout_alignEnd="#+id/seekArc"
android:layout_alignBottom="#+id/minute_progress_number" />
</RelativeLayout>
try this code, may this xml help you..you can take idea from this. if any problem, then ask...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="300dp"
android:layout_height="300dp" >
<com.triggertrap.seekarc.SeekArc
android:id="#+id/seekArc"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerInParent="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:textSize="60sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="H"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:textSize="60sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="M"
android:textSize="30sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
what you are looking for is here in the 2nd answer (not the accepted answer). You use a strut in the middle of the two views.
this is the example given in the answer:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View android:id="#+id/strut"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerHorizontal="true"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignRight="#id/strut"
android:layout_alignParentLeft="true"
android:text="Left"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/strut"
android:layout_alignParentRight="true"
android:text="Right"/>
</RelativeLayout>
I am having a navigation drawer (sliding menu) with header set in my app. I am trying out the following for the headerView.xml
I am setting a background image to the relativeLayout from a particular URL. Instead I would like to have ImageView like below:
By doing this I can use picasso library even for background image that I receive from an URL. This way the image loading is faster I don't need to save the background to any sd card etc.
Here is what I have right now:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LayoutforbgImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:baselineAligned="false"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/LinearLayoutforImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingTop="10dp"
tools:ignore="RtlSymmetry,RtlHardcoded" >
<ImageView
android:id="#+id/imageforprofile"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/profilepic" />
</LinearLayout>
<TextView
android:id="#+id/textforprofile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/LinearLayoutforImage"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingTop="16dp"
android:text="My Name My Name"
android:textColor="#FFFFFF"
android:textStyle="bold"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
<TextView
android:id="#+id/textforprofileemail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textforprofile"
android:layout_toRightOf="#+id/LinearLayoutforImage"
android:gravity="left"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:text="myname#abc.com"
android:textColor="#FFFFFF"
android:textStyle="bold"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
</RelativeLayout>
I am setting background image to layout for: LayoutforbgImage
using:
headerLayout = (RelativeLayout) header.findViewById(R.id.LayoutforbgImage );
BitmapDrawable background = new BitmapDrawable(decodeBase64(coverimage));
headerLayout.setBackgroundDrawable(background);
headerprofileimage = (ImageView) header.findViewById(R.id.imageforprofile);
Picasso.with(this).load(profileImage).placeholder(R.drawable.profilepic).error(R.drawable.profilepic).into(headerprofileimage);
How do I create the ImageView for background image so that it fits perfectly in the layout specified like above?
Try this layout i hope it will help you
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/top_header_bg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_marginRight="20dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
hi try the following code it will help you i didn't make any changes. i simply add an ImageView to your layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LayoutforbgImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:baselineAligned="false"
android:orientation="horizontal" >
<ImageView
android:id="#+id/your_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/top_bar" />
<LinearLayout
android:id="#+id/LinearLayoutforImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingTop="10dp"
tools:ignore="RtlSymmetry,RtlHardcoded" >
<ImageView
android:id="#+id/imageforprofile"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/images12" />
</LinearLayout>
<TextView
android:id="#+id/textforprofile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/LinearLayoutforImage"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingTop="16dp"
android:text="My Name My Name"
android:textColor="#FFFFFF"
android:textStyle="bold"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
<TextView
android:id="#+id/textforprofileemail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textforprofile"
android:layout_toRightOf="#+id/LinearLayoutforImage"
android:gravity="left"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:text="myname#abc.com"
android:textColor="#FFFFFF"
android:textStyle="bold"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
</RelativeLayout>
Try this way hope it will solve your problem
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/topBarRelative"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<ImageView
android:id="#+id/imageHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:src="#drawable/right_top_bg" />
<ImageView
android:id="#+id/imageforprofile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="9dp"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="9dp"
android:layout_toRightOf="#+id/imageforprofile"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textforprofile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:text="My Name My Name"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:id="#+id/textforprofileemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="myname#abc.com"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="#+id/topBarRelative"
android:layout_margin="8dp"
android:background="#drawable/content_bg"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
Screen shot from Eclipse
I have a task, a screen where I want to give the user information in the form of text view of strings and I want to give the user a few choices by including radio buttons.
The problem is it will not fit on the screen. Therefore, I would enlarge the screen so I can add more things. But how?
I have tested with scroll view and various layouts but I don't get it to work.
Below I have my code that I have so far. I have two buttons that should always be at the bottom.
I hope someone can help me. :)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".SetupActivity" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="18dp"
android:orientation="horizontal" >
<Button
android:id="#+id/btnMain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="MainActivity"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="#string/btnCalori" />
<Button
android:id="#+id/btnSetup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/btnSetup" />
</LinearLayout>
<TextView
android:id="#+id/txtViewSetup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/txtViewSetup" />
<TextView
android:id="#+id/txtViewHeader1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout2"
android:layout_below="#+id/txtViewSetup"
android:layout_marginTop="16dp"
android:text="#string/txtViewAttribut" />
<RadioButton
android:id="#+id/radioBtnFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtViewHeader1"
android:layout_below="#+id/txtViewHeader1"
android:text="#string/strFemale" />
<TextView
android:id="#+id/txtViewHeader2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/radioBtnMale"
android:layout_below="#+id/radioBtnMale"
android:layout_marginTop="14dp"
android:text="#string/txtViewWeight" />
<RadioButton
android:id="#+id/radioBtnMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/radioBtnFemale"
android:layout_below="#+id/radioBtnFemale"
android:text="#string/strMale" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".SetupActivity" >
<TextView
android:id="#+id/txtViewSetup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/txtViewSetup" />
<ScrollView
android:id="#+id/scrollview"
android:layout_below="#+id/txtViewSetup"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/txtViewHeader1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="#string/txtViewAttribut" />
<RadioButton
android:id="#+id/radioBtnFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="#string/strFemale" />
<RadioButton
android:id="#+id/radioBtnMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/strMale" />
<TextView
android:id="#+id/txtViewHeader2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="#string/txtViewWeight" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:id="#+id/btnMain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="MainActivity"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="#string/btnCalori" />
<Button
android:id="#+id/btnSetup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/btnSetup" />
</LinearLayout>
</RelativeLayout>