Merge pull request #4423 from tonytamsf/landscape-2

fix layout for 16:9 phone screens, squashed for #4334
This commit is contained in:
H. Lehmann 2020-09-15 10:20:37 +02:00 committed by GitHub
commit dc454b9373
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 10 deletions

View File

@ -45,6 +45,7 @@ import org.greenrobot.eventbus.ThreadMode;
public class CoverFragment extends Fragment {
private static final String TAG = "CoverFragment";
static final double SIXTEEN_BY_NINE = 1.7;
private View root;
private TextView txtvPodcastTitle;
@ -188,20 +189,31 @@ public class CoverFragment extends Fragment {
private void configureForOrientation(Configuration newConfig) {
LinearLayout mainContainer = getView().findViewById(R.id.cover_fragment);
ViewGroup.LayoutParams params = imgvCover.getLayoutParams();
LinearLayout textContainer = getView().findViewById(R.id.cover_fragment_text_container);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) imgvCover.getLayoutParams();
LinearLayout.LayoutParams textParams = (LinearLayout.LayoutParams) textContainer.getLayoutParams();
double ratio = (float) newConfig.screenHeightDp / (float) newConfig.screenWidthDp;
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
double percentageWidth = 0.8;
if (ratio <= SIXTEEN_BY_NINE) {
percentageWidth = (ratio / SIXTEEN_BY_NINE) * percentageWidth * 0.8;
}
mainContainer.setOrientation(LinearLayout.VERTICAL);
if (newConfig.screenWidthDp > 0) {
params.width = (int) (convertDpToPixel(newConfig.screenWidthDp) * .80);
params.width = (int) (convertDpToPixel(newConfig.screenWidthDp) * percentageWidth);
params.height = params.width;
textParams.weight = 0;
imgvCover.setLayoutParams(params);
}
} else {
double percentageHeight = ratio * 0.8;
mainContainer.setOrientation(LinearLayout.HORIZONTAL);
if (newConfig.screenHeightDp > 0) {
params.height = (int) (convertDpToPixel(newConfig.screenHeightDp) * .40);
params.height = (int) (convertDpToPixel(newConfig.screenHeightDp) * percentageHeight);
params.width = params.height;
textParams.weight = 1;
imgvCover.setLayoutParams(params);
}
}

View File

@ -15,8 +15,9 @@
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:layout_marginLeft="64dp"
android:layout_marginRight="64dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:layout_weight="0"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:importantForAccessibility="no"
@ -29,16 +30,17 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<TextView
android:id="@+id/txtvPodcastTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:ellipsize="none"
android:gravity="center_horizontal"
android:maxLines="2"
android:textSize="@dimen/text_size_small"
android:textColor="?android:attr/textColorSecondary"
android:textIsSelectable="true"
tools:text="Podcast" />
@ -47,8 +49,9 @@
android:id="@+id/txtvEpisodeTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:ellipsize="none"
android:gravity="center_horizontal"
android:textSize="@dimen/text_size_small"
android:maxLines="2"
android:textColor="?android:attr/textColorPrimary"
android:textIsSelectable="true"