Why does this button not shown - android

I'm trying to make a footer under view pager but it doesn't appear at all, i have no idea why? here is what i tried, i added the button under view pager but it doesn't appear !
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_survay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/ferani">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="#+id/survey_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
<Button
android:id="#+id/login"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_marginTop="5dp"
android:background="#drawable/primary_round"
android:padding="5dp"
android:layout_weight="1"
android:text="التالي" />
</LinearLayout>
</LinearLayout>

No Need to use three Nested Linear Layout. Try this one:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_survay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/txt_color_white"
>
<android.support.v4.view.ViewPager
android:id="#+id/survey_pager"
android:layout_width="match_parent"
android:layout_above="#+id/login"
android:layout_height="match_parent"
/>
<Button
android:id="#+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:text="التالي" />
</RelativeLayout>

Your viewPager is at match_parent while the button has match_parent too and have a weight
You should try to put 0dp to the width and set a weight to both of them
also your second linear layout seems useless since by default it will apply a vertical orientation

Related

ScrollView with LinearLayout child does not wrap_content correctly

So, I have the following .xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.scopesystems.cityalert.ui.Despre"
tools:showIn="#layout/app_bar_despre"
android:background="#drawable/toolbar_incercare">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/linear_parent">
<RelativeLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.1" />
<RelativeLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="2.8" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--General-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/sectionHeader"
android:text="#string/general"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/despre_general"/>
<!--Evaluti-ne-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/sectionHeader"
android:text="#string/evaluatine"
/>
<!--Confidentialitate si licente-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/sectionHeader"
android:text="#string/confidentialitate"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/despre_politici"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.1" />
</LinearLayout>
</ScrollView>
The issue is that the last ListView is on only 1 row, and it has to be scrolled to display all the items in the list. I tried to add to the linear_parent a height of match_parent but it wont let me, it says that I should use instead wrapcontent. How can i change the layout to display the items on all the screen, not just half?
In this case, On the ScrollView use android:fillViewport="true" and for child of ScrollView android:height="wrap_content".

Android how to fill parent but leave some space

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>

layout does not fit the screen

I have created a layout. But at the bottom there is a white space left. I want the content of the relative layout at the extreme bottom of the screen. i.e seekbar and button at the bottom.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/images">
<com.example.acer.myapplication.ZoomView
android:id="#+id/iop"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<SeekBar
android:id="#+id/seekBar7"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button61"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_below="#id/seekBar7"
android:layout_centerInParent="true"
android:background="#drawable/play" />
</RelativeLayout>
</LinearLayout>
I want the white space at the bottom should be replaced with the content of relative layout.
I have uploaded the image
use this code:
<?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="wrap_content"
android:orientation="vertical"
android:background="#drawable/images">
<com.example.acer.myapplication.ZoomView
android:id="#+id/iop"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<SeekBar
android:id="#+id/seekBar7"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button61"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_below="#id/seekBar7"
android:layout_centerInParent="true"
android:background="#drawable/play" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
instead of wrap_content You should put match_parent.
That would help it out. I hope you know about wrap_content and match_parent.If you don't look at this
https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html

Scroll two horizontal listview and one vertical listview in single activity

I have to scroll both the horizontal listview and vertical listview in single activity.
Below I have posted a screenshot for that:
activity_main.xml:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/home_layout_top"
android:scrollbars="none"
>
<RelativeLayout
android:id="#+id/rl_container_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
android:id="#+id/inc_ads_horizon"
layout="#layout/ads_horizontal_listview_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp" />
<include
android:id="#+id/inc_people_know"
layout="#layout/people_you_know_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/inc_ads_horizon"
android:layout_marginTop="10dp" />
<include
android:id="#+id/inc_listview"
layout="#layout/tab_home_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/inc_people_know"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/no_user_posts_item_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/txt_no_posts_available"
android:textColor="#color/txt_common_black"
android:textSize="#dimen/txt_size" />
</RelativeLayout>
</ScrollView>
tab_home_list_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_layout_bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
<ListView
android:id="#+id/lv_post_home_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="#null"
android:dividerHeight="5dp"
android:scrollbars="none"
android:transcriptMode="alwaysScroll"
android:visibility="gone" />
</LinearLayout>
ads_horizontal_listview_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_horizontalscroll_child"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="#+id/rl_horizontalscroll_parent"
android:layout_marginTop="40dp">
<com.steve.thirdparty.HorizontalListView
android:id="#+id/hlv_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
people_you_know_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_horizontalscroll_second_child"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_horizontalscroll_parent"
android:layout_marginTop="40dp">
<com.steve.thirdparty.HorizontalListView
android:id="#+id/hlv_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
I tried with scrollview.It is not possible to scroll.Let me know is there any other ways to solve this issue.
If I scroll vertical listview to top, it is scrolling vertical listview only.If I am scrolling horizontal listview to the top, it is scrolling both vertical and horizontal listivew.But when I am scolling up, horizontal listview is hiden.
You can get the required views by customizing ScrollView & HorizontalScrollView.
Can check this post https://arunbadole1209.wordpress.com/2011/10/03/how-to-make-simultaneous-scrollable-views-in-android/
Use this xml layout, customize item views according to your actual need:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:nestedScrollingEnabled="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- You can define layout manager here also-->
<android.support.v7.widget.RecyclerView
android:id="#+id/ads_horizon"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/people_know"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/post_home_tab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="10dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

Scroll layout wouldn't show one of my views?

I want to have the following layout :
But when I run the code the first linear layout which contains a relative layout and an image is shown correctly.
Then there is the "view pager" but it is not on the screen.
and then there is a text box and a button which are there too.
So why my view pager is missing?
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
tools:ignore="NestedWeights,ContentDescription" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5" >
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:src="#drawable/sp_page_name"
tools:ignore="ContentDescription" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:padding="#dimen/product_views_horizontal_padding"
tools:ignore="NestedWeights" >
</RelativeLayout>
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager_sharepoint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/TODO"/>
<TextView
android:id="#+id/sharepoint_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/sharepoint_description"
tools:ignore="SelectableText" />
<ImageButton
android:id="#+id/sp_more_info"
android:layout_width="70dp"
android:layout_height="30dp"
android:background="#drawable/more_info_icon"
android:layout_gravity="left"
android:onClick="sp_more"/>
</LinearLayout>
</ScrollView>
The height of your ViewPager is android:layout_height="wrap_content".
So if your ViewPager doesn't contain other views, it won't be visible.
Well, I found out that scrolling views do not work very good together.
For my layout I solve the problem by changing the height and width of the viewpager to static sizes. Actually I defined some different sizes in my dimen.xml files for different screen sizes and use them for the height and width of my view pager.
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
tools:ignore="NestedWeights,ContentDescription" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5" >
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:src="#drawable/sp_page_name"
tools:ignore="ContentDescription" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:padding="#dimen/product_views_horizontal_padding"
tools:ignore="NestedWeights" >
</RelativeLayout>
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager_sharepoint"
android:layout_width="#dimen/viewpager_width"
android:layout_height="#dimen/viewpager_height"
android:contentDescription="#string/TODO"/>
<TextView
android:id="#+id/sharepoint_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/sharepoint_description"
tools:ignore="SelectableText" />
<ImageButton
android:id="#+id/sp_more_info"
android:layout_width="70dp"
android:layout_height="30dp"
android:background="#drawable/more_info_icon"
android:layout_gravity="left"
android:onClick="sp_more"/>
</LinearLayout>
</ScrollView>

Categories

Resources