开发者

UI-Relative layout

开发者 https://www.devze.com 2023-04-08 09:27 出处:网络
I am trying to create a UI using relative layout where in the UI should look as such: In the top of the screen i have a TextView

I am trying to create a UI using relative layout where in the UI should look as such:

  1. In the top of the screen i have a TextView
  2. followed by another TextView
  3. followed by scroll view where in i have to display the text in the scrollable format
  4. in the end i have a imageview.

How can i achieve this. I have tried using the combination of Relative and Linear Layout but the elements gets overlapped. Anyone have any suggestions on how to proceed?

<?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:background="@drawable/background_main"     android:id="@+id/g_description">
<TextView android:id="@+id/titleBar" android:layout_width="f开发者_开发百科ill_parent"
    android:layout_height="wrap_content"  android:background="@drawable/header"
    android:layout_alignParentTop="true" android:gravity="center"
    android:text="@string/aboutus" android:textAppearance="? android:attr/textAppearanceLarge"
    android:textStyle="bold" />

<TextView android:id="@+id/wd_name"
    android:layout_width="fill_parent" android:layout_below="@id/titleBar"
    android:layout_height="wrap_content" android:textStyle="bold"
    android:textColor="#FFFFFF" android:textSize="18dip" 
    android:background="@drawable/background_main" android:gravity="center" />

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrolltext" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:layout_below="@id/wd_name"
    android:padding="5dip">
    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" android:layout_height="fill_parent">

        <TextView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/wd_description" 
            android:layout_width="fill_parent" android:layout_height="wrap_content" 
            android:textSize="14dip" android:textColor="#FFFFFF">
        </TextView> 
        </LinearLayout>

</ScrollView>           


<ImageView android:id="@+id/bottomBar" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:src="@drawable/bottom_bar"
    android:layout_alignParentBottom="true" />


you can achieve it like this:

  1. Take relative layout and put textview in it.
  2. Take another textview and add this to it android:layout_below="id of the 1st textview".
  3. Take scrollview and add this to it android:layout_below="id of the 2nd textview".
  4. Take linear layout inside scrollview.
  5. Put textview inside linear layout.
  6. Take imageview and add this to it android:layout_below="id of the scrollview".

Now your layout is ready and if you get any error then let me know with your code....


If you have a series of elements that you want to flow down the screen, then it sounds like you just need a LinearLayout.


It goes as below. Placing a TextView inside scrollview will make it scrollable. Reset is selfexplanary.

<?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:layout_width="fill_parent" android:text="Below TOP TextView" android:id="@+id/TextView01" android:layout_alignParentTop="true"></TextView>

    <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="TOP TextView" android:id="@+id/TextView02" android:layout_below="@id/TextView01"></TextView>

    <ScrollView android:layout_height="wrap_content" android:layout_width="fill_parent" android:fillViewport="true" android:layout_below="@id/TextView02">
    <TextView android:id="@+id/textView1" android:layout_height="wrap_content" android:text="Scrollable textViewafkasjf;laksjflaskjf;lasjf;alsfjal;sfj;aslfj;aslfja;slfj;aslkfj;asldfj;aslkfjasl;dfj;a asfj aslfj asldfjk as;lfjk asfjka;sldf jl;asj df;asdfjasfj aslfj asljf asjfl;asfasj fasj f;asj flas jf;lasjf;asjkf;las f;asj df;as jf;lasjf ;asjf;asjf;asjf;asjf;asjf;jasf;asfja s;dfa;sf asf jf asf a; sldfja;slfj;asldfjk" android:layout_width="fill_parent"></TextView>
    </ScrollView>
    <ImageView android:src="@drawable/icon" android:layout_height="wrap_content" android:id="@+id/imageView1" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_width="fill_parent"></ImageView>

</RelativeLayout>


It works fine with setting android:orientation="vertical" for each text view.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号