Я использовал constraintLayout
и layout_constraintDimensionRatio="1:1"
(ширина wrap_content
, высота 0dp
(match_constraint
))
В результате я ожидал, что ширина и высота будут 1:1, но это не работает.
Что не так?
Прикрепил код и скриншот.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="@android:color/holo_blue_bright"
android:gravity="center"
android:text="Hello World!11"
app:layout_constraintDimensionRatio="1:1" />
</android.support.constraint.ConstraintLayout>
Я цитирую сайт разработчиков Android о Constraintlayout. https://developer.android.com/reference/android/support/constraint/ConstraintLayout.html#DimensionConstraints
Соотношение :: Вы также можете определить одно измерение виджета как отношение другого. Для этого необходимо, чтобы по крайней мере одно ограниченное измерение было установлено на 0 dp (т. е. MATCH_CONSTRAINT), а для атрибута layout_constraintDimentionRatio задано заданное соотношение. Например:
<Button android:layout_width="wrap_content" android:layout_height="0dp" app:layout_constraintDimensionRatio="1:1" /> will set the height of the button to be the same as its width.
но это не сработало.
ConstrainLayout
? - person Shailesh   schedule 20.05.2017match_parent
не поддерживается. Вам нужно установить0dp
, поэтомуConstraintLayout
установите его соответствующим образом. Проверьте этот stackoverflow .com/questions/37603751/ - person Shailesh   schedule 20.05.2017