Center a TextView: Why it doesn't work? - java

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textColor="#color/red"
android:textStyle="bold"
android:text="#string/desc"
/>
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:textStyle="bold|italic"
android:text="Welcome"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
</RelativeLayout>
I would like to center the second TextView but I can not ... This is the code, you know help me? Where is the error? I'm going crazy!

Add the following to your textview:
android:gravity="center"
But at the same time I would recommend to reconsider your layout as you're having 2 textviews taking the full screen.
Edit
center centers both on horizontal and vertical. If you need only on a specific axis, use one of:
android:gravity="center_horizontal"
or
android:gravity="center_vertical"

try this :
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:textStyle="bold|italic"
android:text="Welcome"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
/>

What about setting it this way
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textColor="#color/red"
android:textStyle="bold"
android:text="#string/desc" />
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:textStyle="bold|italic"
android:text="Welcome"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Alternatively
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout2"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_contet"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textColor="#color/red"
android:textStyle="bold"
android:text="#string/desc" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:textStyle="bold|italic"
android:text="Welcome"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>

Change your layout like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textColor="#color/red"
android:textStyle="bold"
android:text="#string/desc"
/>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="60dp"
android:textStyle="bold|italic"
android:text="Welcome"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
</RelativeLayout>
Always use match_parent instead of fill_parent

// try this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="60dp"
android:textStyle="bold|italic"
android:text="Welcome"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="#id/textView2"
android:layout_marginTop="20dp"
android:textColor="#color/red"
android:text="#string/desc"
android:textStyle="bold"/>
</RelativeLayout>

Related

Layout always fluctuates whenever I try to open the notification shutter or can you please refer some blogs

https://i.stack.imgur.com/VoBbj.gif
the layout is behaving awkward, I am not aware why if anybody could help me with this that will be great.
Whenever I try to open the notification panel, the layout change its position.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="#color/dark"
>
<RelativeLayout
android:id="#+id/top_card"
android:background="#color/lightDark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
>
<LinearLayout
android:id="#+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:background="#drawable/round"
android:layout_alignParentStart="true">
<ImageView
android:layout_width="30dp"
android:layout_height="35dp"
android:src="#drawable/ic_about"
android:id="#+id/info"
android:contentDescription="#string/todo8">
</ImageView>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/musify"
android:textStyle="bold"
android:layout_toEndOf="#+id/search"
android:layout_toStartOf="#+id/menu_bar"
android:textSize="26sp"
android:textColor="#color/day"
android:textAlignment="center"
android:layout_centerInParent="true"
/>
<LinearLayout
android:id="#+id/menu_bar"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:background="#drawable/round"
android:layout_marginRight="20dp">
<ImageView
android:layout_width="30dp"
android:layout_height="35dp"
android:id="#+id/menu"
android:src="#drawable/ic_menu"
android:contentDescription="#string/todo5" />
</LinearLayout>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_card"
android:layout_below="#+id/top_card"
android:id="#+id/music_recycler_view"
>
</androidx.recyclerview.widget.RecyclerView>
<LinearLayout
android:id="#+id/bottom_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:paddingTop="15dp"
android:background="#drawable/round"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/musicbar_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_centerVertical="true"
android:textColor="#color/day"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
>
<TextView
android:id="#+id/musicbar_artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_centerVertical="true"
android:textColor="#color/day"
android:paddingBottom="5dp"
android:layout_marginStart="10dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/round"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_0_00"
android:id="#+id/start_time"
android:textSize="15sp"
android:layout_centerVertical="true"
android:textColor="#color/day"
android:background="#color/lightDark"
android:layout_marginStart="5dp" />
<SeekBar
android:id="#+id/playerseekbar"
android:layout_centerVertical="true"
android:progressDrawable="#drawable/custom_seekbar"
android:progress="0"
android:max="100"
android:thumb="#drawable/custom_thumb"
android:layout_toEndOf="#+id/start_time"
android:layout_toStartOf="#+id/end_time"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_marginEnd="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/end_time"
android:text="#string/_0_00"
android:textSize="15sp"
android:layout_centerVertical="true"
android:textColor="#color/day"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center">
<ImageView
android:id="#+id/prev"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/ic_baseline_skip_previous_24"
android:background="#drawable/round_icon"
android:padding="10dp"
android:contentDescription="#string/todo6" />
<androidx.cardview.widget.CardView
android:id="#+id/play_pause_card"
android:layout_width="90dp"
android:layout_height="100dp"
app:cardBackgroundColor="#color/card"
app:cardCornerRadius="20dp"
app:cardElevation="10dp"
app:cardUseCompatPadding="true"
android:outlineAmbientShadowColor="#color/black"
android:outlineSpotShadowColor="#color/black"
>
<ImageView
android:id="#+id/play_pause_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="#drawable/ic_baseline_play_arrow_24"
android:contentDescription="#string/todo1" />
</androidx.cardview.widget.CardView>
<ImageView
android:id="#+id/next"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/ic_baseline_skip_next_24"
android:background="#drawable/round_icon"
android:padding="10dp"
android:contentDescription="#string/todo7" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Help me with this, I have no clue what's happening!
And it would be great if somebody can give me some ideas for the bottom card to make it look good.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
I added this in the onCreate() method, and it worked.

webview in layout with 4 textviews in top

I do not have much experience with screen layouts xml. I would like to show my screen like this: http://www.consulta-rapida.com/result.png
PS: I would add textvies label3 and Label4 (in red). they are in the figure, but are not in the xml, because I could not aligning them.
Would help to fit these two textviews in my layout below:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:theme="#android:style/Theme.Dialog"
android:layout_height="fill_parent" >
<WebView
android:id="#+id/id_web_view_browser"
android:layout_above="#+id/id_web_view_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<RelativeLayout
android:id="#+id/id_web_view_bar"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:background="#ffffff"
android:orientation="vertical" >
<Button
android:id="#+id/btnCancelar"
android:background="#drawable/btn_red"
android:layout_width="fill_parent"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:text=" Cancelar Corrida "
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top">
<TextView
android:id="#+id/txtLabel1"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:background="#ffffff"
android:maxLines="1"
android:layout_width="wrap_content"
android:text="Label1: Sample1">
</TextView>
<TextView
android:id="#+id/txtLabel2"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#ffffff"
android:text="Label2: Sample2">
</TextView>
</RelativeLayout>
</RelativeLayout>
<?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"
android:theme="#android:style/Theme.Dialog" >
<WebView
android:id="#+id/id_web_view_browser"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/id_web_view_bar"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<RelativeLayout
android:id="#+id/id_web_view_bar"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:background="#ffffff"
android:orientation="vertical" >
<Button
android:id="#+id/btnCancelar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="#drawable/btn_red"
android:text=" Cancelar Corrida "
android:textSize="20sp" />
</RelativeLayout>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/txtLabel1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#ffffff"
android:maxLines="1"
android:text="Label1: Sample1" >
</TextView>
<TextView
android:id="#+id/txtLabel2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="115dp"
android:layout_marginRight="5dp"
android:background="#ffffff"
android:text="Label2: Sample2" >
</TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<TextView
android:id="#+id/txtLabel3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#ffffff"
android:maxLines="1"
android:text="Label1: Sample1" >
</TextView>
<TextView
android:id="#+id/txtLabel4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="115dp"
android:layout_marginRight="5dp"
android:background="#ffffff"
android:text="Label2: Sample2" >
</TextView>
</TableRow>
</TableLayout>
</RelativeLayout>
put them in android:id="#+id/relativeLayout1" relative layout and use layout_below. should work pretty straight forward

Java Android - situate the ListView under all other

i has a layout:
<?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="wrap_content"
android:paddingBottom="4dp"
android:paddingTop="4dp" >
<LinearLayout
android:id="#+id/lineradapter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:layout_marginTop="4dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp">
<FrameLayout
android:id="#+id/frameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="6dp">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:fontFamily="normal"
android:paddingBottom="2dip"
android:paddingTop="6dip"
android:textColor="#525252"
android:textSize="16sp"
android:textStyle="normal" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:fontFamily="normal"
android:paddingBottom="2dip"
android:paddingTop="6dip"
android:text="00:00"
android:textColor="#999999"
android:textSize="14sp"
android:textStyle="italic" />
</FrameLayout>
<TextView
android:id="#+id/desc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingBottom="6dip"
android:textColor="#acacac"
android:textSize="16dp" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#e7e7e7"
android:paddingTop="6dp"
android:paddingBottom="4dp" />
</LinearLayout>
</RelativeLayout>
in this layout i want to position the ListView. At the end, so that you can first see what the top, and then scroll down to see ListView. How to do it? I probyval added before /RelativeLayout>
<LinearLayout
android:id="#+id/comentadapter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:layout_gravity="top|center"/>
<ListView
android:id="#+id/commentList"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
But it is still located at the top.
Use this.
<?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="match_parent"
android:orientation="vertical"
android:paddingBottom="4dp"
android:paddingTop="4dp" >
<LinearLayout
android:id="#+id/lineradapter"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="4dp"
android:layout_weight=".3"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" >
<FrameLayout
android:id="#+id/frameLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="6dp" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:fontFamily="normal"
android:paddingBottom="2dip"
android:paddingTop="6dip"
android:textColor="#525252"
android:textSize="16sp"
android:textStyle="normal" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:fontFamily="normal"
android:paddingBottom="2dip"
android:paddingTop="6dip"
android:text="00:00"
android:textColor="#999999"
android:textSize="14sp"
android:textStyle="italic" />
</FrameLayout>
<TextView
android:id="#+id/desc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingBottom="6dip"
android:textColor="#acacac"
android:textSize="16dp" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#e7e7e7"
android:paddingBottom="4dp"
android:paddingTop="6dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/comentadapter"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".7"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:paddingTop="4dp" />
<ListView
android:id="#+id/commentList"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
</LinearLayout>
Best way to show the listview scrollable with the whole layout you will have to create two layout
for top.xml
<?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="wrap_content"
android:paddingBottom="4dp"
android:paddingTop="4dp" >
<LinearLayout
android:id="#+id/lineradapter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="4dp"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:paddingBottom="2dip"
android:paddingTop="6dip"
android:textColor="#525252"
android:textSize="16sp"
android:textStyle="normal" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:paddingBottom="2dip"
android:paddingTop="6dip"
android:text="00:00"
android:textColor="#999999"
android:textSize="14sp"
android:textStyle="italic" />
<TextView
android:id="#+id/desc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingBottom="6dip"
android:textColor="#acacac"
android:textSize="16dp" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#e7e7e7"
android:paddingBottom="4dp"
android:paddingTop="6dp" />
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:paddingTop="4dp" />
</RelativeLayout>
and create another layout for listview list.xml
<?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="wrap_content"
android:paddingBottom="4dp"
android:paddingTop="4dp" >
<ListView
android:id="#+id/commentList"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
and setcontentview as list.xml and inflate top.xml and add to listview as Header like
ListView list =(ListView)findViewById(R.id.commentList);
LayoutInflater inflater = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View headerView =inflater.inflate(R.layout.top.xml, null);
list.addHeaderView(headerView);

Horizontal rule: how to?

i would like to know how to insert an horizontal rule between the first textview and the second. The code is this. I searched on google and found various codes but they do not work for me
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textColor="#color/red"
android:textStyle="bold"
android:text="#string/desc"
/>
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:textStyle="bold|italic"
android:text="Welcome"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
</RelativeLayout>
Between the two TextViews, add a simple View, give it the background you want (a color or an image) and make it as high as you need the rule to be:
<?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="match_parent"
android:orientation="vertical">
<TextView android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Testing"
android:layout_alignParentTop="true"/>
<View android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#android:color/white"
android:layout_below="#id/text"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Testing"
android:layout_below="#id/divider"/>
</RelativeLayout>
Like the other guy said just add a view between them..so now your code should like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textColor="#color/red"
android:textStyle="bold"
android:text="#string/desc"
/>
<View
android:background="#266E10"
android:layout_height="2dp"
android:layout_width="match_parent"/>
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:textStyle="bold|italic"
android:text="Welcome"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
</RelativeLayout>

Align textview and progressbar in Android XML

I've already tried to align the smallprogressbar with the textview putting them into a linear layout but it doesn't work. Tryed with android:layout_gravity="left" but it crashes.
<?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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/calibration_1"
android:textColor="#33b5e5"
android:textSize="16dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tvNumberWaves"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/calibration_2"
android:textColor="#FFFFFF"
android:textSize="18dp" />
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tvIntervalWaves"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/calibration_3"
android:textColor="#FFFFFF"
android:textSize="18dp" />
<ProgressBar
android:id="#+id/progressBar2"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="#+id/bSetValues"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/calibration_5" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/calibration_6" />
</ScrollView>
</LinearLayout>
Code updated to match your answer.
I put the whole code to show what I have.
Change this line:
android:orientation="vertical"
to this:
android:orientation="horizontal"
Without seeing the rest of your source, I don't know if that will mess up other parts of your layout, so you'll probably want to wrap the TextView and ProgressBar in their own LinearLayout.
<?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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/calibration_1"
android:textColor="#33b5e5"
android:textSize="16dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tvNumberWaves"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/calibration_2"
android:textColor="#FFFFFF"
android:textSize="18dp" />
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tvIntervalWaves"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/calibration_3"
android:textColor="#FFFFFF"
android:textSize="18dp" />
<ProgressBar
android:id="#+id/progressBar2"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="#+id/bSetValues"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/calibration_5" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/calibration_6" />
</ScrollView>
</LinearLayout>

Categories