My goal is to have my chart side by side with my other components.
Iv tried so many hours with different layouts but I cant get it to be side by side.
My idea was to group all components except the chart in one layout and the chart in another, then just put them side by side. But I cant get it to work.
This is how it looks now:
With the code as of now:
<?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:paddingLeft="#dimen/activity_horizontal_margin"
android:id="#+id/mainLayout"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<com.github.mikephil.charting.charts.PieChart
android:id="#+id/pieChartLineLayout"
android:layout_width="150dp"
android:layout_height="200dp" />
<SeekBar
android:layout_width="150dp"
android:layout_height="15dp"
android:id="#+id/seekBar"
android:thumbTint="#color/orange"
android:maxHeight="4dip"
android:minHeight="4dip"
android:layout_marginTop="60dp"
android:layout_below="#+id/pieChartLineLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<SeekBar
android:layout_width="150dp"
android:layout_height="15dp"
android:id="#+id/seekBar2"
android:maxHeight="4dip"
android:minHeight="4dip"
android:thumbTint="#color/red"
android:layout_below="#+id/textView4"
android:layout_alignRight="#+id/textView2"
android:layout_alignEnd="#+id/textView2" />
<SeekBar
android:layout_width="150dp"
android:layout_height="15dp"
android:maxHeight="4dip"
android:minHeight="4dip"
android:thumbTint="#color/blue"
android:id="#+id/seekBar3"
android:layout_below="#+id/textView5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="0%"
android:textColor="#FFFFFF"
android:background="#drawable/rounded_corner_orange"
android:id="#+id/textView"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:layout_marginBottom="16dp"
android:layout_alignBottom="#+id/seekBar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Carbohydrates"
android:id="#+id/textView2"
android:textStyle="bold"
android:paddingLeft="10dp"
android:layout_alignBottom="#+id/textView"
android:layout_toRightOf="#+id/textView"
android:layout_toEndOf="#+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="0%"
android:textColor="#FFFFFF"
android:background="#drawable/rounded_corner_reds"
android:id="#+id/textView3"
android:layout_marginTop="12dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:layout_below="#+id/seekBar"
android:layout_toLeftOf="#+id/textView4"
android:layout_toStartOf="#+id/textView4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Proteins"
android:id="#+id/textView4"
android:paddingLeft="10dp"
android:textStyle="bold"
android:layout_alignTop="#+id/textView3"
android:layout_alignLeft="#+id/textView2"
android:layout_alignStart="#+id/textView2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="0%"
android:textColor="#FFFFFF"
android:background="#drawable/rounded_corner_blue"
android:id="#+id/textView5"
android:layout_marginTop="14dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:layout_below="#+id/seekBar2"
android:layout_toLeftOf="#+id/textView6"
android:layout_toStartOf="#+id/textView6" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Fats"
android:id="#+id/textView6"
android:textStyle="bold"
android:paddingLeft="10dp"
android:layout_alignTop="#+id/textView5"
android:layout_alignLeft="#+id/textView4"
android:layout_alignStart="#+id/textView4" />
</RelativeLayout>
User LinearLayout as your container (with horizontal orientation). Then add pie chart to it and another, vertical LinearLayout with seek bars in it.
Related
I am using relative layout in my android app.
Following is my main.xml.
<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:gravity="fill"
tools:context="com.example.asdf.MainActivity" >
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:scaleType="fitXY"
android:src="#drawable/bgg" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="22dp"
android:layout_marginTop="22dp"
android:gravity="center"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:text=" Factualnote is an web annotation application, which helps the users to mark the specific text, element, page, video, etc in a web page and share it to like-minded people.\r\n \r\nAs we know the relevant data has been wide-spreaded across various sites under many intentions, factualnote is a type of social software tool in which factual data are brought forward or narrow down to the web users."
android:textColor="#ffffff"
android:textSize="25sp"
android:textStyle="normal|italic" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<EditText
android:id="#+id/url"
android:layout_width="290dp"
android:layout_height="33dip"
android:layout_above="#+id/button_show"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:background="#ffffff"
android:ems="17"
android:hint="#string/edit_hint"
android:radius="10dp"
android:singleLine="true"
android:text="http://www.zeptoh.com/lynked/sel.html"
android:textColor="#000000"
android:textSize="16sp" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#drawable/blue_button"
android:text="#string/button_title"
android:textColor="#ffffff" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/undo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="9"
android:background="#drawable/blue_button2"
android:text="#string/undo"
android:textColor="#ffffff" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="9"
android:background="#drawable/blue_button2"
android:text="Mark"
android:textColor="#ffffff" />
<Button
android:id="#+id/done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="10"
android:background="#drawable/blue_button2"
android:text="Generate"
android:textColor="#ffffff" />
<Button
android:id="#+id/redo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="9"
android:background="#drawable/blue_button2"
android:text="#string/redo"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:id="#+id/rl2"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<EditText
android:id="#+id/name"
android:layout_width="250dp"
android:layout_height="33dip"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#ffffff"
android:ems="17"
android:layout_gravity="center_horizontal"
android:hint="Enter Title"
android:singleLine="true"
android:textColor="#000000"
android:textSize="16sp" />
<EditText
android:id="#+id/desc"
android:layout_width="250dp"
android:layout_height="33dip"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:background="#ffffff"
android:ems="17"
android:layout_gravity="center_horizontal"
android:hint="Description about your note"
android:singleLine="true"
android:textColor="#000000"
android:textSize="16sp" />
<TextView
android:id="#+id/privateText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/desc"
android:layout_below="#+id/desc"
android:layout_marginTop="10dp"
android:text="Private Note:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
android:textSize="20sp"
android:checked="true"
android:buttonTint="#color/desing_color"
android:textStyle="bold" />
<RadioGroup
android:id="#+id/radioSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/privateText"
android:layout_toRightOf="#+id/privateText"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:text="Yes"
android:buttonTint="#color/desing_color"
android:textColor="#ffffff"
android:textSize="15sp"
android:textStyle="bold" />
<RadioButton
android:id="#+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/privateText"
android:layout_marginLeft="14dp"
android:layout_toRightOf="#+id/yes"
android:text="No"
android:textColor="#ffffff"
android:textSize="15sp"
android:checked="true"
android:buttonTint="#color/desing_color"
android:textStyle="bold" />
</RadioGroup>
<Button
android:id="#+id/generate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#drawable/blue_button"
android:layout_below="#+id/radioSex"
android:layout_marginTop="10dp"
android:layout_marginLeft="70dp"
android:textColor="#ffffff"
android:text="Generate Note" />
<Button
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_below="#+id/radioSex"
android:background="#drawable/blue_button"
android:layout_marginTop="10dp"
android:layout_marginLeft="200dp"
android:textColor="#ffffff"
android:text="Back" />
</RelativeLayout>
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
I put progress bar to center in horizontal and vertical. But that is placed on top of the screen only.
When I remove Linear layout rl2, progress bar appears center.
What I need to do to get progress bar in center even I have rl2.
Try adding
android:layout_centerInParenta="true"
to the progressbar and tell me if it works.
Did you try to remove android:gravity="fill" from the main container? (the first relative layout, the one that contains all the layout)
add the following line in your xml file,
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
if its not work, then first add progressbar and then add your views. Maybe it will work.
I am trying to align my buttons at the bottom of the screen using layouts but I cannot figure what's wrong with my code. I have tried several options by nesting different layouts but with no good outcome. it looks like this right now
And my code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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:id="#+id/relLayout"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:clickable="true"
android:focusableInTouchMode="true"
tools:context="com.example.aurora.personalinformation.MainActivity">
<!-- Make the parent view clickable and focusable -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/title"
android:layout_centerHorizontal="true"
android:id="#+id/title"
android:textColor="#FF0000"
android:textSize="25dp"
android:textAlignment="center" />
<TextView
android:id="#+id/nameLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="15dp"
android:layout_marginTop="40dp"
android:layout_below="#id/title"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText android:id="#+id/edit_name"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter name"
android:layout_alignBottom="#id/nameLable"
android:layout_toRightOf="#+id/phoneLable"
android:layout_toEndOf="#+id/phoneLable"
/>
<TextView
android:id="#+id/addressLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/address"
android:textColor="#000000"
android:textSize="15dp"
android:textStyle="bold"
android:layout_alignBottom="#+id/addressField"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:id="#+id/addressField"
android:layout_weight="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your address"
android:layout_below="#id/edit_name"
android:layout_alignLeft="#id/edit_name"
android:layout_alignStart="#id/edit_name" />
<TextView
android:id="#+id/phoneLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/phone"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="15dp"
android:layout_below="#id/addressField"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp"/>
<EditText
android:id="#+id/phoneField"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your phone number"
android:layout_below="#id/addressField"
android:layout_toRightOf="#id/phoneLable"
android:layout_toEndOf="#id/phoneLable" />
<TextView
android:id="#+id/emailLable"
android:layout_below="#id/phoneLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/email"
android:textColor="#000000"
android:textSize="15dp"
android:textStyle="bold"
android:layout_marginTop="20dp"/>
<EditText
android:id="#+id/emailField"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your email"
android:layout_below="#id/phoneField"
android:layout_alignLeft="#id/phoneField"
android:layout_alignStart="#id/phoneField" />
<TextView
android:id="#+id/genderLable"
android:layout_below="#id/emailLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gender"
android:layout_marginTop="20dp"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="15dp" />
<Spinner
android:id="#+id/gender"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="#array/gender"
android:layout_alignTop="#+id/genderLable"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="#+id/emailField"
android:layout_alignStart="#+id/emailField" />
<TextView
android:id="#+id/country"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Country"
android:textColor="#000000"
android:textSize="15dp"
android:textStyle="bold"
android:layout_below="#id/gender"
android:layout_marginTop="15dp"/>
<AutoCompleteTextView
android:id="#+id/countryField"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your email"
android:layout_below="#id/gender"
android:layout_toRightOf="#id/phoneLable"
android:layout_toEndOf="#id/phoneLable" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:id="#+id/buttonCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
just give your last RelativeLayout like this:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom"
android:layout_below="#+id/countryField"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:id="#+id/buttonCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
One more thing there is no meaning to give an orientation to RelativeLayout.
I have to align one TextView in the middle of a ImageView-->ImageButton, I know that is not difficult but my problems come because the image can have variable size , so when I got different images, the text view moves around, and don't stay aligned horizontally in the middle of the image.
A image can help to my explanation:
At this moment I set the image and text like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_circuitomedico"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:elevation="12dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="#string/professional"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/circ_profesionall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="#+id/textView1"
android:layout_toEndOf="#+id/textView1"
android:text="#string/medico_test"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_alignStart="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="12dp"
android:text="#string/medical_service"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/circ_spin_tipus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_alignStart="#+id/textView3"
android:layout_marginTop="12dp"
android:layout_below="#+id/textView3" />
<Spinner
android:id="#+id/circ_spin_tipocons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/circ_spin_tipus"
android:layout_alignStart="#+id/circ_spin_tipus"
android:layout_marginTop="12dp"
android:layout_below="#+id/circ_spin_tipus" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/circ_spin_tipocons"
android:layout_alignStart="#+id/circ_spin_tipocons"
android:layout_below="#+id/circ_spin_tipocons"
android:text="#string/circuit_curesnafres"
android:layout_marginTop="12dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_alignStart="#+id/textView4"
android:layout_below="#+id/textView4"
android:layout_marginTop="12dp"
android:text="#string/circuit_nhc"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/circ_spin_tipolesion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView5"
android:layout_alignStart="#+id/textView5"
android:layout_below="#+id/textView5"
android:layout_marginTop="12dp" />
<Spinner
android:id="#+id/circ_spin_local"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/circ_spin_tipolesion"
android:layout_alignStart="#+id/circ_spin_tipolesion"
android:layout_below="#+id/circ_spin_tipolesion"
android:layout_marginTop="12dp" />
<Spinner
android:id="#+id/circ_spin_escalas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/circ_spin_local"
android:layout_alignStart="#+id/circ_spin_local"
android:layout_below="#+id/circ_spin_local"
android:layout_marginTop="12dp" />
<EditText
android:id="#+id/circ_box_descrip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/circ_spin_escalas"
android:layout_alignStart="#+id/circ_spin_escalas"
android:layout_below="#+id/circ_spin_escalas"
android:layout_marginTop="12dp"
android:layout_marginRight="20dp"
android:layout_marginEnd="20dp"
android:ems="12"
android:inputType="textMultiLine" >
</EditText>
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/circ_box_descrip"
android:layout_alignStart="#+id/circ_box_descrip"
android:layout_below="#+id/circ_box_descrip"
android:layout_marginTop="12dp"
android:src="#drawable/button_picture" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton1"
android:layout_marginTop="30dp"
android:layout_toRightOf="#+id/textView1"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
This is Best as per your Requirement :-
<?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">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/img"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="im in Center"
android:textStyle="bold"
android:textSize="30sp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
Thank you and have a best Programming..
Try to replace your textview which you want to align with this:
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageButton1"
android:layout_alignTop="#+id/imageButton1"
android:layout_toRightOf="#+id/imageButton1"
android:gravity="center"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
This will make your text view aligned with your imageview and text will be shown with center gravity.
Problem is that if your image will be less than the text size or text lines .
Try this-->
<RelativeLayout
android:id="#+id/relative"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/your_image" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/image"
android:layout_alignLeft="#id/image"
android:layout_alignRight="#id/image"
android:layout_alignTop="#id/image"
android:gravity="center"
android:maxLines="5"
android:textColor="#000000"
android:textSize="8dp"
android:textStyle="bold" />
</RelativeLayout>
Try this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="100">
<ImageView
android:id="#+id/image1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
android:src="#drawable/clock_number"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
android:layout_marginStart="12dp"
android:text="Hello World!" />
</LinearLayout>
Hi I have a problem with centering TextView in ScrollView. I want to center my TextViews with ids hajs, textView01, textView02 vertically in order to be in the center of height of imageViews. It's strange because in the Android Studio design I see everything right, but when I try on device I get these TextViews in the top of the TextView.
<?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">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:fillViewport="true">
<RelativeLayout
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal" >
<TextView
android:id="#+id/hajs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageView1"
android:layout_centerInParent="true"
android:layout_toLeftOf="#+id/imageView1"
android:background="#41BF17"
android:gravity="center_vertical|center|center_horizontal"
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFF"
android:textSize="70sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#41BF17"
android:gravity="center"
android:text="#string/zaoszczedziles"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFF"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView2"
android:adjustViewBounds="true"
android:background="#41BF17"
android:maxWidth="100dp"
android:src="#drawable/moneybag" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/hajs"
android:background="#41BF17"
android:gravity="center"
android:text="#string/dni_bez_papierosow"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFF"
android:textStyle="bold" />
<ImageView
android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView3"
android:adjustViewBounds="true"
android:background="#41BF17"
android:maxWidth="100dp"
android:src="#drawable/calendar" />
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/ImageView01"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/hajs"
android:layout_alignTop="#+id/ImageView01"
android:layout_centerInParent="true"
android:background="#41BF17"
android:gravity="center"
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFF"
android:textSize="70sp" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
I want TextView to end at red Line in picture below instead of start line of three blue textviews .
How ?
layout.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="49dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_margin="20dp"
android:id="#+id/relative">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/progress"
android:id="#+id/imageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="Progress"
android:id="#+id/textView"
android:autoText="false"
android:textColor="#1A237E"
android:textSize="#dimen/abc_dialog_padding_top_material"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/textView2"
android:layout_toEndOf="#+id/textView2"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text=" absolute"
android:id="#+id/textView2"
android:textIsSelectable="true"
android:textSize="#dimen/abc_action_bar_icon_vertical_padding_material"
android:textColor="#FF6D00"
android:gravity="center"
android:layout_alignBottom="#+id/above"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/above"
android:paddingBottom="10dp"
android:background="#ffd8f1ff"
android:padding="5dp"
android:layout_below="#+id/textView"
android:layout_alignRight="#+id/textView"
android:layout_alignEnd="#+id/textView"
android:layout_gravity="right"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text=" percentage"
android:id="#+id/textView4"
android:textSize="#dimen/abc_action_bar_icon_vertical_padding_material"
android:textColor="#FF6D00"
android:gravity="center"
android:layout_below="#+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/below"
android:paddingTop="10dp"
android:background="#ffd8f1ff"
android:padding="5dp"
android:layout_below="#+id/above"
android:layout_alignLeft="#+id/above"
android:layout_alignStart="#+id/above"
android:layout_gravity="right" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text=" goal"
android:id="#+id/textView5"
android:textSize="#dimen/abc_action_bar_icon_vertical_padding_material"
android:textColor="#FF6D00"
android:gravity="center"
android:layout_below="#+id/textView4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/goal"
android:paddingTop="10dp"
android:background="#ffd8f1ff"
android:padding="5dp"
android:layout_below="#+id/below"
android:layout_alignLeft="#+id/below"
android:layout_gravity="right"
android:layout_alignParentLeft="false" />
thanx in advance .
First, right align your three blue TextViews with the Progress TextView. That way, all the blue TextViews will be right aligned. Then, instead of using layout_gravity=right, use gravity=right. That will right align the text within the blue TextViews. Finally, make all the blue TextViews be to_rightOf textview4, which is the longest TextView. Doing these adjustments will make the layout look like this:
Here's the code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/relative"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_margin="20dp"
android:layout_marginTop="49dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"/>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/textView2"
android:layout_toRightOf="#+id/textView2"
android:autoText="false"
android:gravity="center"
android:text="Progress"
android:textColor="#1A237E"
android:textSize="#dimen/abc_dialog_padding_top_material"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignBottom="#+id/above"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:gravity="center"
android:text=" absolute"
android:textColor="#FF6D00"
android:textIsSelectable="true"
android:textSize="#dimen/abc_action_bar_icon_vertical_padding_material"/>
<TextView
android:id="#+id/above"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/textView"
android:layout_alignRight="#+id/textView"
android:layout_below="#+id/textView"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/textView4"
android:background="#ffd8f1ff"
android:gravity="right"
android:padding="5dp"
android:paddingBottom="10dp"
android:text="18%"
/>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView2"
android:gravity="center"
android:text=" percentage"
android:textColor="#FF6D00"
android:textSize="#dimen/abc_action_bar_icon_vertical_padding_material"/>
<TextView
android:id="#+id/below"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/above"
android:layout_alignRight="#+id/textView"
android:layout_alignStart="#+id/above"
android:layout_below="#+id/above"
android:background="#ffd8f1ff"
android:padding="5dp"
android:paddingTop="10dp"
android:text="12.4%"
/>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView4"
android:gravity="center"
android:text=" goal"
android:textColor="#FF6D00"
android:textSize="#dimen/abc_action_bar_icon_vertical_padding_material"/>
<TextView
android:id="#+id/goal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/below"
android:layout_alignParentLeft="false"
android:layout_alignRight="#id/textView"
android:layout_below="#+id/below"
android:background="#ffd8f1ff"
android:gravity="right"
android:padding="5dp"
android:paddingTop="10dp"
android:text="0%"/>
Instead you can put those two horizontal TextView inside a
LinearLayout and set the LinearLayout below the percentage's TextView. Doing this you can have more customizability with the alignment of the TextView.
In your case this was different than what I normally set it up. But in this case its easier to add
<View
android:layout_width="0dp"
android:layout_alignRight="#+id/textView"
android:layout_alignEnd="#+id/textView"
android:id="#+id/holder"
android:layout_height="0dp"/>
and then for the views you want to align to the right side add
android:layout_toLeftOf="#+id/holder"