List Fragment height is not working properly, it only shows 1st row of list, other rows of list dont show. I used wrap content for height but not working. If i run Fragment directly it shows all rows but if i add fragment in my main activity its show single row. Other rows show if i change height of fragment manually like layout_height="100dp";. I want fragment height to be dynamic. This my main activity xml code:
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/app_bar_welcome" android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.app.Fragments.SpecialListFragment"
android:id="#+id/fragment3"
tools:layout="#layout/fragment_special_list" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#efefef">
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
If i change height of fragment to 100dp:
fragment list height 100dp
If i wrap content fragment:
wrap content height of list fragment
Related
Hello I'm trying to make an application that has multiple bottomnaviagtion tabs.
Currently it works because fragment data (for example, images) are static. However, if I want to make them dynamic, I'll have to create a preloader.
So I want to display a loading layout (for example R.layout.loading) UNTIL (async) function has completed and obtained data from server. Then I want to replace the layout in the fragment with a new layout (R.layout.datafragment)
Fragment onCreateView:
return inflater.inflate(R.layout.loading, container, false);
In summary it should work exactly like youtube bottom tabs.
You should create in your activity layout a placeholder for those dynamic fragments and a loader which is by default gone, but when you start loading data from the server you should make it visible (loader). Then, when you load necessary data, just start fragment transition and place whatever fragment you have loaded.
Your parent activity's layout should be like 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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Navigation View and Fragment Container-->
</RelativeLayout>
<RelativeLayout
android:id="#+id/progress_layout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
</RelativeLayout>
Then you simply show/hide progressLayout based on your requirement. Thanks
In xcode I can display a PDF as a single continuous page, with the PDF width being equal to screen width and then the vertical scroll being the height of PDF for said width. No problems
Currently converting same app to Android and having some difficulty implementing same PDF view
Basically I have a PDF page that is very long (single page). I don't want to swipe between pages, but instead like in my iOS app, have the PDF document fill the Android screen width wise, and then scroll vertically to show rest of PDF
I'm using com.github.barteksc.pdfviewer.PDFView to render my PDF
In my xml for the activity I have:
<?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"
android:fillViewport="true">
tools:context=".ProfileActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.github.barteksc.pdfviewer.PDFView
android:id="#+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</ScrollView>
I've tried changing the layout_height to "wrap_content" for scrollView, Linear and pdf, as that would seem appropriate, but whenever I do this I get a blank screen. It seems that doing so resulting in no height attribute so the view collapses completely
I get:
What I want:
Would really appreciate any further help, this is really my only sticking point. I wish android had PDFKit (similar) as I found that quite easy to use and implement
Well there is an answer!
I had to 'upgrade' to the latest version: 3.1.0-beta.1 and use the:
.pageFitPolicy(FitPolicy.WIDTH)
Combined with my XML:
<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"
android:fillViewport="true">
tools:context=".AboutActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical">
<com.github.barteksc.pdfviewer.PDFView
android:id="#+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</ScrollView>
Worked perfectly. I hope this helps others
I have a viewPager with infinite loop, but i want to set a border to highlight the current image.
In my main activity i've the adapterPageAdapter and the custom ViewPager (that is clickable).
I think that is easy, but i need help.
Something like this:
Thanks
> Place image view inside another layout set the background color of
> parent layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/border"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="1dp">
<ImageView
android:id="#+id/imageViewImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:foregroundGravity="center_horizontal"/>
</RelativeLayout>
> inside PagerAdapter instantiateItem method when you are setting bitmap
> to imageView, also set backgroud color to layout.
final RelativeLayout border = (RelativeLayout) view.findViewById(R.id.border);
border.setBackgroundColor(Color.RED);
When the phone is in portrait mode, it shows the title and image at the top and below that there's the button and ListView with comments. However when I turn the phone to be in landscape mode, the button and ListView dissapear and only the title and image are shown. I basically can't scroll below the image anymore.
There is a third element -- a TextView for the body -- that is also inside that ScrollView: each layout will either have that TextView with content or an image. The same thing happens when it's the TextView that has content and no image. This does not occur when the image or text don't take up the entire screen though.
Portrait mode:
Landscape mode:
Accompanying code:
<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="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="net.vannevel.redditapp.activities.PostActivity">
<TextView
android:id="#+id/postDetailTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="#000" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/postDetailImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/postDetailBody"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/postDetailViewOnlineButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onViewOnlineButtonClicked"
android:text="View original source" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="COMMENTS" />
<ListView
android:id="#+id/postDetailCommentList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
So your problem is that the items you have inside the scroll view are taller than the screen height in landscape. Even if you scroll inside the ScrollView, there's nothing you can do once you get to the end of it. All the elements placed outside the ScrollView are going to be off screen and placed outside any scrollable container.
I can see 3 possible solutions:
1 - set fixed size to the scroll view so that it doesn't occupy the whole screen, so that you let the other views in. Not practical, however: phone in landscape means short height and you have to fit a picture and list with comments...
2 - have a different layout for landscape - picture on left, list with comments on right
3 - get rid of the ScrollView and set everything above the ListView as a ListView header (addHeaderView)
For example:
Step 1 - extract everything you have on top of the ListView and put it into a different layout file - let's call it header.xml
Step 2 - inflate the layout:
View headerView = inflater.inflate(R.layout.header, listView, false);
Step 3 - initialize the items on the header just like you do it now
Step 4 - set the view as the header of the list ListView:
listView.addHeaderView(headerView, null, false);
The side effect of this approach is that the header, being part of the ListView now, it will scroll as you scroll the list. Also, it will offset your position in the adapter by 1.
Change:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:orientation="vertical">
Or implemet two layouts portland and landscape orientation.
According to the following picture:
I want something like this
the ListView is not a NavigationDrawer, it's a part of the Activity.
Items the ListView are columns of a database and when user selected Each of them, on the left side(Activity), other fields of that column should be displayed.
How can I do this?
Try it like this
<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="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0"
android:layout_height="match_parent"
android:layout_weight="1">
//Your UI
</LinearLayout>
<LinearLayout
android:layout_width="0"
android:layout_height="match_parent"
android:layout_weight="1">
//Your ListView
</LinearLayout>
</LinearLayout>
So your layout will have fragments one a left fragment and one a right one
XML
<LinearLayout
orientation:horizontal>
<FrameLayout
id=leftFragment
weight=1/>
<FrameLayout
id=rightFragment
weight=1/>
</LinearLayout>
Java Code
FragmentManager fm=getFragmentManager();
fm.replace(R.id.leftFragment,new LeftFragment());
fm.commit();
Similarly for Right Fragment
You should use a LinearLayout with Horizontal orientation, then have two layout, one for the left side of the screen and one for the right side of the screen (with your ListView). Then you should use the layout_weight attribute for each layout by declaring like 0.7 for the right one (ListView) and 0.3 for the left one, it should looks like your picture