Tweetview images truncated

fabric
embeddedtweet

#1

Hi, I’m using tweetviews to display embedded tweets in our news articles. But the tweets which have images appear truncated.

Example screenshot:

Web url for this news : https://www.filmipop.com/news/movies/just-married-akshay-kumar-weds-bhumi-pednekar-in-toilet-ek-prem-katha/articleshow/57272600

I’m using tweetview to display this image. Code is as follows:

Xml for layout to display tweet.

<?xml version="1.0" encoding="utf-8"?>
   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/ll_tweet_view"
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
 </RelativeLayout>

Adding tweet dynamically:

public static View getTweetViewForTweet(final Context context, final String element) {
        long id = Long.parseLong(getAtrribute(element, "id"));
        final ViewGroup mTweetView = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.layout_tweet_view, null);
        TweetUtils.loadTweet(id, new Callback<Tweet>() {
            @Override
            public void success(Result<Tweet> result) {
                final TweetView tweetView = new TweetView(context, result.data,
                        R.style.tw__TweetLightWithActionsStyle);
                mTweetView.addView(tweetView);
            }

            @Override
            public void failure(com.twitter.sdk.android.core.TwitterException e) {

            }

        });
        return mTweetView;
    }

I’d appreciate some help. Thanks.


#2

Currently the default aspect ratio for TweetViews is 3:2. Potentially you could override getAspectRatioForPhotoEntity to modify the aspect ratio.


#3

Hi EricFrohnhoefer, Thanks for your advice. I tried overriding getAspectRatioForPhotoEntity and changed the aspect ratio to 0.5 which solved my problem. But it has certain side-effects on other tweets. In some tweets the image got stretched from the original one. The method has a check for adjusting ratio on basis of photocount, but in case of different tweets (each with a single photo and different sizes), this doesn’t work. Is there a way to check media entity size in any other callback so that I can adjust the aspect ratio on the basis of that?