Is there a way to create a visual divider in a relative layout similar to the way you can using a list divider?
This is what I have currently.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_height="wrap_content"
android:text="Screen Ratio:"
android:id="#+id/ScreenRatio"
android:layout_width="100dip"
android:layout_alignTop="#+id/ratio_spinner"
android:layout_alignBottom="#+id/ratio_spinner"
android:gravity="center_vertical"/>
<Spinner android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/ScreenRatio"
android:id="#+id/ratio_spinner"/>
<TextView
android:layout_height="wrap_content"
android:text="Units:"
android:id="#+id/Units"
android:layout_width="wrap_content"
android:layout_toLeftOf="#+id/unit_spinner"
android:layout_alignTop="#+id/unit_spinner"
android:layout_alignBottom="#+id/unit_spinner"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"/>
<Spinner android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/ScreenRatio"
android:layout_below="#+id/ratio_spinner"
android:id="#+id/unit_spinner"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Clear"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:gravity="fill"
android:paddingLeft="50dip"
android:paddingRight="50dip"/>
</RelativeLayout>
So far , i have tried to add separator inside the TableLayout using the below code:
<View android:id="#+id/view_separator"
android:background="#FFFFFF"
android:layout_centerVertical ="true"
android:layout_width = "fill_parent"
android:layout_height="2dip"
android:layout_alignParentTop="true"/>
It may helps you, just try it.
Related
This my code in this I have been using scrollView and inside it two textViews to add more content but it is working only when there is one textView please what changes i do to add more content?And here I want space between those textViews(content) but in my code i am trying for that but the content is overlapped and there is no proper space between contents.please help me..!
<?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"
tools:context="com.example.hp.kludge.AndroidActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:weightSum="1">
<TextView
android:id="#+id/tvA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="ANDROID"
android:textColor="#f6080101"
android:textColorHighlight="#df1425"
android:textSize="35dp"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:background="#e62027"
android:layout_height="2dp"
android:layout_below="#+id/tvC" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:fillViewport="true"
android:orientation="vertical">
<TextView
android:id="#+id/tvWhat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tvC"
android:layout_marginTop="44dp"
android:text="What is Android?"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="22dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Content"
android:id="#+id/tvt" />
</ScrollView>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="#+id/butNext"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#abc3fb" />
</RelativeLayout>
I am struggling big time with trying to make a simple layout with two TextView:s under each other on the left and corresponding two TimePicker:s under each other on the right. However, whichever view I use or attributes I choose that seem relevant I do not get the desired outcome. Here is my current try:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1"
>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
>
<TextView
android:layout_column="1"
android:id="#+id/text_start_time"
android:text="#string/start_time"
android:gravity="center_horizontal"
/>
<TimePicker
android:id="#+id/time_picker_start"
android:timePickerMode="spinner"
android:layout_marginTop="-25dp"
android:layout_marginBottom="-25dp"
android:layout_gravity="center"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
>
<TextView
android:layout_column="1"
android:id="#+id/text_end_time"
android:text="#string/end_time"
android:layout_gravity="center_horizontal"
/>
<TimePicker
android:id="#+id/time_picker_end"
android:timePickerMode="spinner"
android:layout_marginTop="-25dp"
android:layout_marginBottom="-25dp"
/>
</TableRow>
<TableRow>
<Button
android:layout_column="2"
android:layout_width="match_parent"
android:text="#string/button_calculate"
android:gravity="center"
android:onClick="calculateWorkingTime"
/>
</TableRow>
</TableLayout>
This gives the following output
Where is "Start"?
As you can see "Start" is not even shown! I would like to align "Start" with the vertical center of the TimePicker spinner. How to do that?
First, don't use a TableLayout. Use Linears, as you are a beginner and they're easier to use and understand. Here's what you should do:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/text_start_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/start_time"
android:gravity="center_horizontal"
/>
<TimePicker
android:id="#+id/time_picker_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner"
android:layout_marginTop="-25dp"
android:layout_marginBottom="-25dp"
android:layout_gravity="center"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/text_end_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/end_time"
android:gravity="center_horizontal"
/>
<TimePicker
android:id="#+id/time_picker_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner"
android:layout_marginTop="-25dp"
android:layout_marginBottom="-25dp"
android:layout_gravity="center"
/>
</LinearLayout>
<Button
android:layout_column="2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="#string/button_calculate"
android:gravity="center"
android:onClick="calculateWorkingTime"
/>
</LinearLayout>
What I've done is creating a Linear Layout and, into it, another two with orientation:horizontal, which makes the elements appear one next to each other.
Also, I've put width and height to all the elements, what is very important.
I've put wrap_content, if you want to change it, no problem.
I didn't test it, if there's any error, just coment
Hope it helps!
I would like to align the view element in the current layout with the view element which I included through tag in Android.
Layout1: (Layout1.xml)
<?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="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/click_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/desc"
android:padding="4dp"
android:src="#drawable/icon_click" />
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="bottom"
android:paddingLeft="8dp"
android:paddingTop="6dp"
android:text="#string/textview1"
/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:text="#string/textView2"
/>
</RelativeLayout>
</LinearLayout>
Layout2:
<?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" >
<include
android:id="#+id/includedLayout"
layout="#layout/Layout1" />
<View
android:id="#+id/seperator"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:alpha="0.3"
android:background="#FFFFFF" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- I want to align this layout with relative layout present in the
Layout1.xml file which is included above -->
</LinearLayout>
</LinearLayout>
I want to align the second LinearLayout in the Layout2.xml with the RelativeLayout in the Layout1.xml file which is included in the Layout2.xml file.
Please let me know if anyone knows the solution.
Thanks.
whay dont you try putting the layout part that you want to align in to another file and only include that file in to the your layout2.xml and manually coding remining part in the layout2.xml.
What i mean is to take
`
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="bottom"
android:paddingLeft="8dp"
android:paddingTop="6dp"
android:text="#string/textview1"
/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:text="#string/textView2"
/>
</RelativeLayout>`
this part in to another separate file and manually add imageview in to layout2.xml
I have added supports-screens to manifest, all UI elements values are in dip.
Why then I'm changing screen type in Graphical Layout my layout doesn't re-sizes?
I'm using LinearLayout, maybe better way is RelativeLayout?
Please help;
My Layout code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="#000000">
<TextView
android:id="#+id/a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="20dip"
android:textStyle="bold"
android:layout_centerInParent="true"
android:text="Login" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="#drawable/background"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/Image"
android:layout_width="280dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="20dip"
android:layout_height="35dip"
android:src="#+drawable/logo_big"/>
<EditText
android:id="#+id/LoginName"
android:hint="Email"
android:layout_marginTop="20dip"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:inputType="textEmailAddress"/>
<EditText
android:hint="Password"
android:layout_marginTop="0dip"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:inputType="textPassword"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:password="true"
android:id="#+id/Password"/>
<Button
android:id="#+id/LogIn"
android:layout_marginTop="20dip"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:text="#+string/LogIn"/>
<TextView
android:id="#+id/TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:gravity="center"
android:layout_marginTop="10dip"
android:textStyle="bold"
android:textSize="18dp"
android:text="#+string/DontHaveAnAccount"/>
<Button
android:id="#+id/SingUpNow"
android:layout_width="fill_parent"
android:layout_marginTop="10dip"
android:layout_height="45dip"
android:src="#+drawable/gray_button"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:background="#+drawable/primary_button"
android:clickable="true"
android:text="#+string/SingUpNow"/>
<Button
android:textColor="#FFFFFF"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:layout_marginTop="10dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:id="#+id/ForgotYourPassword"
android:background="#+drawable/secondary_button"
android:text="#+string/ForgotYourPassword"/>
</LinearLayout>
</LinearLayout>
Help;
This tips maybe help you...
Avoid the use of graphical layout, just check you code there will be some hard code value or maybe there Absolute Layout..
To re-size the screen layout use Relative Layout... that will be fit for all screen..
I have the following code....and I can't seem to get the ads to run outside my scroll view. I have tried to follow other questions on this topic. please assist. All of my adds are showing on top of my content. I would prefer the ads run outside my scroll view.
my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxxxxxxxxx"
ads:loadAdOnCreate="true" />
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layoutbottom"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:padding="5dp" >
<!-- android:layout_height="456dp" -->
<TextView
android:id="#+id/txtPlaceName"
style="#style/HeaderText"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/txtAddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/txtStory"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/txtURL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Try adding android:layout_alignParentTop="true" on your AdView and android:layout_below="#id/adView" on your ScrollView.