Android- Proper positioning of layouts

為{幸葍}努か 提交于 2020-01-13 16:54:37

问题


I cant seem to properly position my layouts the way I want them to be. What my layout looks like is like this:

LinearLayout
  LinearLayout
      ListView

  LinearLayout
      TextView
      TextView
      TextView
      Button   

My aim is to have it like this:

Any thoughts on this please as to what Layouts i will use?

Help will be appreciated


回答1:


try this

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/homeTableLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
     >

 <LinearLayout
     android:layout_centerInParent="true"
     android:layout_width="fill_parent"
    android:layout_height="100dip"
    android:background="@android:color/holo_blue_dark"
    >
    <!-- arrange your lables and button here -->

    </LinearLayout>
   <LinearLayout
    android:layout_width="100dip"
    android:layout_height="fill_parent" 
    android:background="@android:color/holo_purple"
    android:layout_marginLeft="20dip"
    >
       <ListView
           android:layout_width="fill_parent" 
           android:layout_height="fill_parent"

           ></ListView>
   </LinearLayout>
</RelativeLayout>

look the wireframe below . you can set corner-radius and add controls in it.




回答2:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/layout2"
    android:layout_width="fill_parent"
    android:layout_height="200dip"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="100dip"
        android:layout_weight="1" >
    </ListView>
</LinearLayout>

<LinearLayout
    android:id="@+id/layout1"
    android:layout_width="100dip"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="TextView" />
</LinearLayout>


</RelativeLayout>



回答3:


You can use the Relative layout for this as follows

<?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:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/first_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="20dip" >

        <Button
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:id="@+id/btn2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/btn1" />

        <Button
            android:id="@+id/btn3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/btn2" />

        <Button
            android:id="@+id/btn4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/btn3" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/second_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_toRightOf="@+id/first_layout" >

        <GridView
            android:id="@+id/gridview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
        </GridView>

        <Button
            android:id="@+id/btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true" />
    </RelativeLayout>

</RelativeLayout>


来源:https://stackoverflow.com/questions/15401073/android-proper-positioning-of-layouts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!