<?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" >
<android.support.v4.view.ViewPager android:id="#+id/groups_of_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="100"
android:text="There are not place for me" />
</LinearLayout>
In the code above ViewPager occupies all of the place. How to make it occupy as much space as much as a content requires. As layout's "wrap_content" property.
UPD:
ViewPager is filled with:
<?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">
<TextView android:id="#+id/group_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/group_active"
/>
</LinearLayout>
I want to ViewPager have size as musch as TextView in code above. How to make it?
If you are going to use android:layout_weight you have to set the android:layout_height to 0dip like in this example.
<?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" >
<android.support.v4.view.ViewPager android:id="#+id/groups_of_content"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="3"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:text="Must there be place for me" />
</LinearLayout>
Related
The title isn't good but i didn't know how else to describe
I have a relative layout with 2 elements, some container and a button at bottom.
I want the container fill all the space in the relativelayout leaving just the space enough to put the button
here is an example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout //i'm using linearlayout as an example, it could be anything here
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/b3"
android:gravity="center"
android:orientation="vertical">
</LinearLayout>
<Button
android:id="#+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="asdasdasdasdasdasdasdasd" />
</RelativeLayout>
here is how i want it look like
The red means the relavitive layout, the green the linear layout, and the yellow means the button...
how can i make it?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/red"
android:padding="5dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/b"
android:background="#color/green">
</LinearLayout>
<Button
android:id="#+id/b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="this is the button"
android:background="#color/yellow"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorAccent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="#+id/b3"
android:layout_margin="4dp"
android:background="#color/colorPrimary"
android:gravity="center"
android:orientation="vertical">
</LinearLayout>
<Button
android:id="#+id/b3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="asdasdasdasdasdasdasdasd" />
</RelativeLayout>
This should give you something close to what you want:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout //i'm using linearlayout as an example, it could be anything here
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
</LinearLayout>
<Button
android:id="#+id/b3"
android:layout_width="wrap_content"
android:layout_height="0px"
android:layout_weight="1"
android:text="asdasdasdasdasdasdasdasd" />
</LinearLayout>
I want to add a button at the end of a list view. I have the following xml file. The list view appears with its contents, but the button does not show up.
<?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"
android:minWidth="25px"
android:minHeight="25px">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/myListView" />
<Button
android:text="Project Download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/download" />
</LinearLayout>
The problem is with the attribute android:layout_height="match_parent" in your ListView. match_parent means that the listview will fill all the space. The correct way is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:weight="1"
android:id="#+id/myListView" />
<Button
android:text="Project Download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/download" />
</LinearLayout>
Your button is not shown because your ListView took the whole space hiding your button as you set its layout_height to match_parent. match_parent will take the whole available space. So change it to wrap_content like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_parent"
android:id="#+id/myListView" />
<Button
android:text="Project Download"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/download" />
</LinearLayout>
wrap_content will wrap your view to the least available height/width without hiding anything or making anything unclear.
i have the same problem, and solved.
you only need wrap that layout into ScrollView
<ScrollView 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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_transaction_history"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</android.support.v7.widget.RecyclerView>
<Button
android:id="#+id/btn_history_load_more"
style="?borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:paddingBottom="#dimen/margin_big"
android:paddingTop="#dimen/margin_large"
android:text="#string/text_btn_load_more"
android:textColor="#009CDE"
android:textSize="#dimen/text_size_medium" />
</LinearLayout>
</ScrollView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<Button
android:layout_alignParentBottom="true"
android:text="Project Download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/download" />
<ListView
android:layout_above="#id/download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/myListView" /></RelativeLayout>
I have a ListView and a TextView. When there is a condition the TextView is visible else no.
The XML code is this.
<?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"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:fontFamily="sans-serif-light"
android:visibility="gone"
android:text="No controls"/>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
The TextView is centered only in horizontal, why not in vertical? If I change the layout_height of listview in match_parent is centered also in vertical but I don't want a match_parent to layout height of listview. There are other solutions?
use this.....
<?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"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="No controls" />
</RelativeLayout>
In Xamarin, how can I create and position a container over a Layout?
Here is my Layout XML code:
<?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">
<FrameLayout
android:id="#+id/mapWithOverlay"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
How can I create a container that has a TextView and a Button and then position this container where I want on top of the FrameLayout?
Thanks in advance
Use Relative Layout, you can arrange the elements where ever you want.
Check here Relative Layout
Here you go:
<?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="horizontal"
android:padding="5dip" >
<LinearLayout
android:id="#+id/thumbnail"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
<FrameLayout
android:id="#+id/mapWithOverlay"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="#+id/thumbnail" />
</RelativeLayout>
This is the basic XML file
<?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"
android:background="#color/white"
>
<!--top part-->
<include layout="#layout/top" android:layout_width="fill_parent"
android:layout_height="0dp" android:layout_weight="1"/>
<!--content area-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:background="#ff6600"
>
</LinearLayout>
<!--bottom part-->
<include layout="#layout/bottom" android:layout_width="fill_parent"
android:layout_height="0dp" android:layout_weight="1"/>
</LinearLayout>
When I load it in the emulator, it looks like on the image below.
What am I doing wrong?
EDIT
This is top and bottom XML. Basic as well.
<?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"
>
<ImageView
android:id="#+id/bottom_image"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:adjustViewBounds="true"
android:src="#drawable/bottom"
/>
</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"
>
<ImageView
android:id="#+id/top_image"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:adjustViewBounds="true"
android:src="#drawable/top"
/>
Please try following
Top.xml
<?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="wrap_content"
android:id="#+id/top"
>
<ImageView
android:id="#+id/top_image"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:adjustViewBounds="true"
android:src="#drawable/top"
android:scaleType="fitXY"/>
</LinearLayout>
Bottom.xml
<?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="wrap_content"
android:id="#+id/bottom"
>
<ImageView
android:id="#+id/bottom_image"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:adjustViewBounds="true"
android:src="#drawable/bottom"
android:scaleType="fitXY"/>
</LinearLayout>
and finally Main.xml
<?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"
android:background="#000000"
>
<!--top part-->
<include layout="#layout/top" android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<!--content area-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ff6600"
>
</LinearLayout>
<!--bottom part-->
<include layout="#layout/bottom" android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
This will solve your problem
remove the android:layout_weight from your top and bottom parts (and set it to anything you want, different than 0, in the content area). This way the content will take all the available space.
On what you did, you only told the content to take 5/7 of the available space, which will behave as you show depending on your screen proportions.
And on a real Smartphone? Is there a space, too?
Have you got the newest Version of the SDK Platform tools?
Check for layout_bottom and layout_top definition. Most probably these layouts have marginTop and marginBottom set.