Note that there are some explanatory texts on larger screens.

plurals
  1. POImages in portrait mode not displaying inside list view
    text
    copied!<p>I am trying to display a fb like newsfeed inside my android app (one photo with a tagline). To do so, I have created the following code:</p> <p>HomeFragment.java</p> <pre><code>@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_home, container, false); newsFeedDescriptions = getResources().getStringArray(R.array.news_feed_description); newsFeedPics = getResources().obtainTypedArray(R.array.news_feed_pics); newsFeedLayout = (RelativeLayout)rootView.findViewById(R.id.news_feed); newsFeedList=(ListView)rootView.findViewById(R.id.list_news_feed); newsFeedItems = new ArrayList&lt;NewsFeedItem&gt;(); newsFeedItems.add(new NewsFeedItem(newsFeedDescriptions[0], newsFeedPics.getResourceId(0, -1))); newsFeedItems.add(new NewsFeedItem(newsFeedDescriptions[1], newsFeedPics.getResourceId(1, -1))); newsFeedItems.add(new NewsFeedItem(newsFeedDescriptions[2], newsFeedPics.getResourceId(2, -1))); newsFeedPics.recycle(); newsFeedAdapter = new NewsFeedListAdapter(getActivity().getApplicationContext(),newsFeedItems); newsFeedList.setAdapter(newsFeedAdapter); return rootView; } </code></pre> <p>Fragment_home.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/news_feed" android:background="@color/theme_background"&gt; &lt;ScrollView android:layout_width="match_parent" android:layout_height="487dp" &gt; &lt;ListView android:id="@+id/list_news_feed" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="start" android:background="@color/theme_background" android:divider="@color/list_divider" android:dividerHeight="1dp" /&gt; &lt;/ScrollView&gt; &lt;/RelativeLayout&gt; </code></pre> <p>NewsfeedListAdapter.java</p> <pre><code>package com.example.makemyday; import java.util.ArrayList; import android.app.Activity; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; public class NewsFeedListAdapter extends BaseAdapter { private Context context; private ArrayList&lt;NewsFeedItem&gt; newsFeedItems; public NewsFeedListAdapter(Context context, ArrayList&lt;NewsFeedItem&gt; newsFeedItems){ this.context = context; this.newsFeedItems = newsFeedItems; } @Override public int getCount() { return newsFeedItems.size(); } @Override public Object getItem(int position) { return newsFeedItems.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); convertView = mInflater.inflate(R.layout.newsfeed_item, null); } ImageView img = (ImageView) convertView.findViewById(R.id.newsfeed_image); TextView description = (TextView) convertView.findViewById(R.id.newsfeed_description); img.setImageResource(newsFeedItems.get(position).getImage()); description.setText(newsFeedItems.get(position).getDescription()); // displaying count // check whether it set visible or not return convertView; } } </code></pre> <p>NewsfeedItem.java</p> <pre><code>public class NewsFeedItem { private String description; private int image; public NewsFeedItem(){} public NewsFeedItem(String description, int image){ this.description = description; this.image = image; } public String getDescription(){ return this.description; } public int getImage(){ return this.image; } public void setDescription(String description){ this.description = description; } public void setImage(int image){ this.image = image; } } </code></pre> <p>newsfeed_rectangle.xml</p> <pre><code>&lt;shape xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;gradient android:endColor="@color/theme_foreground" android:centerColor="@color/theme_foreground" android:startColor="@color/theme_foreground" android:angle="270" /&gt; &lt;corners android:radius="3dp" /&gt; &lt;padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /&gt; &lt;/shape&gt; </code></pre> <p>newsfeeditem.xml </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="48dp" android:background="@drawable/newsfeed_rectangle"&gt; &lt;ImageView android:id="@+id/newsfeed_image" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_marginLeft="12dp" android:layout_marginRight="12dp" android:layout_centerVertical="true" /&gt; &lt;TextView android:id="@+id/newsfeed_description" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_below="@+id/newsfeed_image" android:minHeight="12dp" android:textColor="@color/blue" android:gravity="center_vertical" android:paddingRight="40dp"/&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Only the photos in landscape show properly, but not the photos taken in potrait mode.. I dont understand why</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload