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
Related
I am working on an Android project in which I have two different types of Chat possibilities. One is for Groups and other is for private or one to one communication. Now, all the Groups and Users the logged-in user can chat with is shown in ConversationActivity.
For this, I have prepared two lists in the UI, and contents will be added to each list by an Async method. Each List has a separate adapter, with which I will be able to easily identify, which item was clicked.
This mechanism is working just fine, except that when the activity is opened, the list look they are layered on top of each other, obviously that is not the intention. So I indicated in the RelativeLayout, to position it above another, that also didn't help.
How can I display two lists with two different adapters in one activity page?
activity_conversations.xml :
<?xml version="1.0" encoding="UTF-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip"
android:layout_above="#+id/privateRelativeLay"
>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/conversationList"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip"
android:id="#+id/privateRelativeLay">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/privateConversationList"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
<ListView
android:id="#+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:dividerHeight="1dp" />
</android.support.v4.widget.DrawerLayout>
ConversationActivity.java
public class ConversationActivity extends ApplicationDrawerLoader {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_conversations);
if (isOnline()) {
new getConversationsForLoggedInUser(this).execute();
new getPrivateChannelsForLoggedInUser(this).execute();
}
public class getPrivateChannelsForLoggedInUser extends AsyncTask<Void,Void,ResponseEntity<PrivateChannel[]>>{
#Override
protected void onPostExecute(ResponseEntity<PrivateChannel[]> responseEntity) {
privateChannelConversationList = (ListView) findViewById(R.id.privateConversationList);
privateConversationAdapter = new PrivateConversationAdapter(conversationActivity, privateMapList);
privateChannelConversationList.setAdapter(privateConversationAdapter);
// On click adapter excluded
}
public class getConversationsForLoggedInUser extends AsyncTask<Void, Void, ResponseEntity<RestGroupAccount[]>> {
#Override
protected void onPostExecute(ResponseEntity<RestGroupAccount[]> responseEntity) {
super.onPostExecute(responseEntity);
groupAccountConversationList = (ListView) findViewById(R.id.conversationList);
groupConversationAdapter = new GroupConversationAdapter(conversationActivity, groupAccountMapList);
groupAccountConversationList.setAdapter(groupConversationAdapter);
// On click adpater excluded
}
}
I hope this much information is sufficient, if anything else is required, let me know. Any help would be nice. Thank you.
This is how it looks : screenshot :
They display on top of eachother because you put them both in a separate RelativeLayout that have the same positioning properties (none).
One fix would be to put both listViews in a LinearLayout instead. You can provide this LinearLayout with an orientation attribute vertical or horizontal, depending on how you want to display them, then use the layout_weight attribute to determine what portion of the screen each listviews occupies.
For example:
<LinearLayout 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="0dp"
android:layout_weight="1" >
</ListView>
<ListView
android:id="#+id/listView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</ListView>
</LinearLayout>
Note: fill_parent is legacy. Use match_parent instead.
It is because height of your both List Views is fill_parent. Try using wrap content or in your case i don't know how exactly do you want both List views to be displayed but I would suggest you use linear layout with orientation that you want and assign weights.
The layouts stack on each other in RelativeLayout as long as the cover the whole screen width and height.
Also fill_parent attribute value is deprecated now it is better to use match_parent.
I'm working on a information orientated app using the master/detail flow and so far, so good. I would like to add images to the TextView, but it's formatted differently then what I've experienced in the past and I'm lost. from my understanding of what I've read while searching is that the scrolling text is "newer" when generating the Master/detail activity, therefore I haven't found any information on this specific issue. I would also like to pass the images in using the content activity, so it would be-
addItem(new Item(ID,Name,Detail,Image1,Image2));
what the detail XML file looks like
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/bobblehead_detail"
style="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:textIsSelectable="true"
tools:context="com.example.johnson.fallout4bobbleheadlocations.BobbleheadDetailFragment" />
I tried adding ImageView's under it, but I received errors.
tl;dr I would like to add 2 images under the scrolling TextView.
I am not sure if I clearly understand what you mean but looking at your xml it seems to me that you need to add a layout (either relative or linear) to your xml file and then add a textview and two imageviews (or whatever you want) into that layout.
Something like this:
<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="match_parent"
android:padding="16dp" tools:context="com.example.somefragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/some_id2"
android:text="Here is your text"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/some_id"
android:src="#drawable/image1"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/some_id3"
android:src="#drawable/image2"/>
</RelativeLayout>
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
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.
Suppose I have a layout file structured like this:
<LinearLayout android:id="#+id/main" android:orientation="vertical" android:animateLayoutChanges="true">
<EditText>
<TextView android:id="#+id/header1">
<LinearLayout android:id="#+id/insertionPoint" android:orientation="vertical" android:animateLayoutChanges="true">
</LinearLayout>
<TextView android:id="#+id/header2">
</LinearLayout>
I want to dynamically add text fields to the Layout insertionPoint and I would like to see an animation of the elements below it (in this case, header2) sliding down.
Using android:animateLayoutChanges only animates the elements in the layout insertionPoint, so there is no animation for header2. What should I do?
Just to be more clear: what I would like to do here is something like the animations that we can see in the People app in ICS when we add more fields, like telephone numbers, to a contact.
Thank you!
API 16 added the LayoutTransition.CHANGING animation type, however it is disabled by default.
To enable:
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.main);
linearLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
Nice DevBytes video: https://www.youtube.com/watch?v=55wLsaWpQ4g