2017-11-06 4 views
0

私は制約レイアウトをインクルードタグとして追加する主なレイアウトを持っています。 私の主なレイアウトです。メインレイアウトに制約レイアウトを適切に含めるにはどうすればいいですか?

<android.support.constraint.ConstraintLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:id="@+id/logo1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:contentDescription="@null" 
     android:paddingTop="@dimen/multi_screen_medium_padding" 
     android:paddingStart="@dimen/multi_screen_medium_padding" 
     android:paddingEnd="@dimen/multi_screen_medium_padding" 
     android:src="@drawable/logo1" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintHorizontal_bias="0.0" 
     android:layout_marginLeft="16dp" 
     android:layout_marginTop="8dp" 
     android:layout_marginRight="16dp"/> 

    <ImageView 
     android:id="@+id/logo2" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:contentDescription="@null" 
     android:src="@drawable/logo2" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/logo1" 
     android:layout_marginTop="8dp" 
     app:layout_constraintDimensionRatio="w,1:1"/> 

</android.support.constraint.ConstraintLayout> 

私の要件以下のように、2つのimageViewsで構成されてい

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/text1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/text1" 
     android:textAlignment="center" 
     android:textColor="@color/app_theme_primary" 
     android:textSize="@dimen/large_header_text_size" /> 

    <TextView 
     android:id="@+id/version_number" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/version_number" 
     android:textAlignment="center" 
     android:textColor="@color/common_main_background" 
     android:textSize="@dimen/secondary_text_size"/> 

    <TextView 
     android:id="@+id/develop_text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/padding_10dp" 
     android:gravity="center" 
     android:text="@string/developed_text" 
     android:textColor="@color/common_main_background" 
     android:textStyle="bold" /> 

    <include layout="@layout/common_layout"/> 

    <TextView 
     android:id="@+id/trademarks" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:text="@string/trademarks" 
     android:textAlignment="center" 
     android:paddingTop="@dimen/multi_screen_small_padding" 
     android:textColor="@color/common_main_background" 
     android:textSize="@dimen/secondary_text_size" /> 
    </LinearLayout> 

私の制約レイアウトが
1.Constraintレイアウトがメインレイアウトに適切に装着されなければならないが、ここで私が直面する問題は、最後のTextViewです(IDです:商標)が画面上に表示されない。
2. 2番目の画像(logo2)は画面サイズごとに適切に調整する必要があります。

どうすればいいですか?前もって感謝します。

+0

同じ画像の異なる解像度を使用する必要があります。 [this](https://stackoverflow.com/questions/37207443/how-to-put-single-image-for-different-screen-size)を読んでください。 – gbruscatto

+0

ソースコードのチャンクを適切にフォーマットするには、Ctrl + KまたはCmd + Kを使用する必要があります。 –

+0

この縫い目は複雑です。だから最善の解決策は何gbruscattoを行うか、パーセンテージでそれを行うことです:https://stackoverflow.com/questions/37318228/how-to-make-constraintlayoutwork-with-percentage-values –

答えて

0

、私自身は私の質問のための完璧な答えを得ました。マイmain_layout.xml

<?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" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fillViewport="true"> 

<android.support.constraint.ConstraintLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 


    <TextView 
     android:id="@+id/app_name" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="@string/app_name" 
     android:textAlignment="center" 
     android:textColor="@color/theme_primary" 
     android:textSize="@dimen/large_header_text_size" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent"/> 

    <TextView 
     android:id="@+id/version_number" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="@string/version_number" 
     android:textAlignment="center" 
     android:textColor="@color/common_main_background" 
     android:textSize="@dimen/secondary_text_size" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/app_name"/> 

    <TextView 
     android:id="@+id/develop_text" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:paddingTop="@dimen/padding_10dp" 
     android:text="@string/developed_by" 
     android:textColor="@color/common_main_background" 
     android:textStyle="bold" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/version_number"/> 

    <include 
     android:id="@+id/common_layout" 
     layout="@layout/common_layout" 
     android:layout_width="0dp" 
     android:layout_height="324dp" 
     android:layout_marginTop="@dimen/multi_screen_medium_padding" 
     app:layout_constraintBottom_toTopOf="@+id/trademarks" 
     app:layout_constraintDimensionRatio="1:0.90" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/develop_text"/> 

    <TextView 
     android:id="@+id/trademarks" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="@dimen/multi_screen_medium_padding" 
     android:text="@string/trademarks" 
     android:textAlignment="center" 
     android:textColor="@color/common_main_background" 
     android:textSize="@dimen/secondary_text_size" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/common_layout"/> 

</android.support.constraint.ConstraintLayout> 
</ScrollView> 

私は、XML(secondary_layoutが含ま
の下にチェックしてください。xml)

<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/main_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ImageView 
    android:id="@+id/logos" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:adjustViewBounds="true" 
    android:contentDescription="@null" 
    android:src="@drawable/logos" 
    app:layout_constraintBottom_toTopOf="@+id/alliance" 
    app:layout_constraintHorizontal_bias="0.5" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    android:layout_marginLeft="@dimen/multi_screen_medium_padding" 
    android:layout_marginRight="@dimen/multi_screen_medium_padding" 
    android:layout_marginTop="@dimen/multi_screen_medium_padding" 
    android:layout_marginBottom="@dimen/multi_screen_medium_padding"/> 

<ImageView 
    android:id="@+id/alliance" 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:layout_marginLeft="0dp" 
    android:layout_marginRight="0dp" 
    android:layout_marginStart="8dp" 
    android:layout_marginTop="@dimen/multi_screen_medium_padding" 
    android:contentDescription="@null" 
    android:src="@drawable/alliance" 
    app:layout_constraintBottom_toBottomOf="@+id/main_layout" 
    app:layout_constraintDimensionRatio="3:1" 
    app:layout_constraintHorizontal_bias="0.50" 
    app:layout_constraintLeft_toLeftOf="@+id/logos" 
    app:layout_constraintRight_toRightOf="@+id/logos" 
    app:layout_constraintTop_toBottomOf="@+id/logos" 
    app:layout_constraintVertical_bias="0.50"/> 
</android.support.constraint.ConstraintLayout> 

ありがとうございます。

0

タイトルはうまく質問に合うが、ここではいくつかのヒントや解決策はありません:あなたはまた、ロゴ2

2 - 上の親ビューの下に制約が不足している

の1-内容をラップして1,1を与えることは良い考えではありません

解決策:ビューを下にしてから高さを0dpにします。

<android.support.constraint.ConstraintLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:id="@+id/logo1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:contentDescription="@null" 
     android:paddingTop="@dimen/multi_screen_medium_padding" 
     android:paddingStart="@dimen/multi_screen_medium_padding" 
     android:paddingEnd="@dimen/multi_screen_medium_padding" 
     android:src="@drawable/logo1" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintHorizontal_bias="0.0" 
     android:layout_marginLeft="16dp" 
     android:layout_marginTop="8dp" 
     android:layout_marginRight="16dp" /> 

    <ImageView 
     android:id="@+id/logo2" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_marginBottom="8dp" 
     android:layout_marginTop="8dp" 
     android:contentDescription="@null" 
     android:src="@drawable/logo1" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintDimensionRatio="w,1:1" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/logo1" /> 

</android.support.constraint.ConstraintLayout> 
+0

素早く応答してくれてありがとう、しかし私がこのようにすれば、ロゴ2が大きくなりすぎる。 – kodali

+0

こんにちはMohammad、私も私の質問とコードを編集して、確認してください、あなたは何か提案を与えることができますか?明確化が必要な場合はお知らせください。 – kodali

+0

ソースコードのチャンクを適切にフォーマットするには、Ctrl + KまたはCmd + Kを使用する必要があります。 –

0

ImageViewのScaleTypeプロパティを使用してください。

CENTER - 画像を中央に配置しますが、画像を拡大縮小しません。

CENTER_CROP - 画像を一様に拡大/縮小します。

CENTER_INSIDE - エッジを正確に一致させるのではなく、コンテナ内のイメージを中央に配置します。

FIT_CENTER - 中央から画像を拡大/縮小します。

FIT_END - 画像をコンテナの端からスケールします。

FIT_START - イメージをコンテナの先頭から拡大/縮小します。

FIT_XY - コンテナのx座標とy座標から画像を塗りつぶします。

MATRIX - 描画時にイメージマトリックスを使用してスケールします。 例:数時間のhardwork後

android:scaleType="center" 

このドキュメントをチェックアウトClick here

+0

scaleTypeを使用すると、アスペクト比は失われますが、私は正しいのでしょうか? – kodali

+0

はい、いいえ。 uのようなscaleTypeの値がいくつかありますが、中央の場合は画像全体が表示されますが、画像が大きい場合は膨大なスペースが必要です。しかし、もしあなたがcenter_cropを使うなら、uは画像を拡大/縮小できます。 Uはアスペクト比を失いますが、均一に調整しようとします。とにかくそれは動作します。私はいつも自分の画像にcenter_cropを使用しています。異なる値を試してみてください。あなたの要件に合ったものを見てください –

関連する問題