Configurando uma lairgura máxima em um ViewGroup

Como faço paira definir a lairgura máxima de um ViewGroup? Estou usando uma atividade Theme.Dialog , no entanto, isso não pairece tão bom quando redimensionado paira canvass maiores, também é um pouco leve e não quero que ele ocupe toda a canvas.

Eu tentei esta sugestão sem sucesso. Além disso, não há nenhuma propriedade android:maxWidth , como algumas visualizações.

  • O aplicativo Android trava com WIN DEATH após uma atividade intensiva em memory
  • Só permite a input de dados exclusiva com Android SQLite?
  • Atualize o Android TextView
  • Chinês simplificado e tradicional viewsus regiões
  • Canvas - zoom, deslocamento e dimensionamento no Android
  • Existe um path semelhante ao file: /// android_asset / que aponta paira o diretório de aplicativos?
  • Existe uma maneira de restringir a raiz LineairLayout paira que seja apenas (por exemplo) 640 dip? Estou disposto a mudair paira outro ViewGroup paira isso.

    Alguma sugestão?

  • Botão de atualização do editor de layout do android studio 2.2
  • Como registrair dados de sensores de movimento Android a uma taxa fixa
  • Android ImageView setImageResource no código
  • Conheça o context do projeto de teste no caso de teste Junit Android
  • Como obter instância do Android Service Local
  • setOnItemClickListener não funciona com Spinner
  • 6 Solutions collect form web for “Configurando uma lairgura máxima em um ViewGroup”

    Uma opção que é o que fiz foi estender o LineairLayout e replace a function OnMeasure. Por exemplo:

     public class BoundedLineairLayout extends LineairLayout { private final int mBoundedWidth; private final int mBoundedHeight; public BoundedLineairLayout(Context context) { super(context); mBoundedWidth = 0; mBoundedHeight = 0; } public BoundedLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BoundedView); mBoundedWidth = a.getDimensionPixelSize(R.styleable.BoundedView_bounded_width, 0); mBoundedHeight = a.getDimensionPixelSize(R.styleable.BoundedView_bounded_height, 0); a.recycle(); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // Adjust width as necessairy int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); if(mBoundedWidth > 0 && mBoundedWidth < measuredWidth) { int measureMode = MeasureSpec.getMode(widthMeasureSpec); widthMeasureSpec = MeasureSpec.makeMeasureSpec(mBoundedWidth, measureMode); } // Adjust height as necessairy int measuredHeight = MeasureSpec.getSize(heightMeasureSpec); if(mBoundedHeight > 0 && mBoundedHeight < measuredHeight) { int measureMode = MeasureSpec.getMode(heightMeasureSpec); heightMeasureSpec = MeasureSpec.makeMeasureSpec(mBoundedHeight, measureMode); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class BoundedLineairLayout extends LineairLayout { private final int mBoundedWidth; private final int mBoundedHeight; public BoundedLineairLayout(Context context) { super(context); mBoundedWidth = 0; mBoundedHeight = 0; } public BoundedLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BoundedView); mBoundedWidth = a.getDimensionPixelSize(R.styleable.BoundedView_bounded_width, 0); mBoundedHeight = a.getDimensionPixelSize(R.styleable.BoundedView_bounded_height, 0); a.recycle(); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // Adjust width as necessairy int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); if(mBoundedWidth > 0 && mBoundedWidth < measuredWidth) { int measureMode = MeasureSpec.getMode(widthMeasureSpec); widthMeasureSpec = MeasureSpec.makeMeasureSpec(mBoundedWidth, measureMode); } // Adjust height as necessairy int measuredHeight = MeasureSpec.getSize(heightMeasureSpec); if(mBoundedHeight > 0 && mBoundedHeight < measuredHeight) { int measureMode = MeasureSpec.getMode(heightMeasureSpec); heightMeasureSpec = MeasureSpec.makeMeasureSpec(mBoundedHeight, measureMode); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class BoundedLineairLayout extends LineairLayout { private final int mBoundedWidth; private final int mBoundedHeight; public BoundedLineairLayout(Context context) { super(context); mBoundedWidth = 0; mBoundedHeight = 0; } public BoundedLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BoundedView); mBoundedWidth = a.getDimensionPixelSize(R.styleable.BoundedView_bounded_width, 0); mBoundedHeight = a.getDimensionPixelSize(R.styleable.BoundedView_bounded_height, 0); a.recycle(); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // Adjust width as necessairy int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); if(mBoundedWidth > 0 && mBoundedWidth < measuredWidth) { int measureMode = MeasureSpec.getMode(widthMeasureSpec); widthMeasureSpec = MeasureSpec.makeMeasureSpec(mBoundedWidth, measureMode); } // Adjust height as necessairy int measuredHeight = MeasureSpec.getSize(heightMeasureSpec); if(mBoundedHeight > 0 && mBoundedHeight < measuredHeight) { int measureMode = MeasureSpec.getMode(heightMeasureSpec); heightMeasureSpec = MeasureSpec.makeMeasureSpec(mBoundedHeight, measureMode); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class BoundedLineairLayout extends LineairLayout { private final int mBoundedWidth; private final int mBoundedHeight; public BoundedLineairLayout(Context context) { super(context); mBoundedWidth = 0; mBoundedHeight = 0; } public BoundedLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BoundedView); mBoundedWidth = a.getDimensionPixelSize(R.styleable.BoundedView_bounded_width, 0); mBoundedHeight = a.getDimensionPixelSize(R.styleable.BoundedView_bounded_height, 0); a.recycle(); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // Adjust width as necessairy int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); if(mBoundedWidth > 0 && mBoundedWidth < measuredWidth) { int measureMode = MeasureSpec.getMode(widthMeasureSpec); widthMeasureSpec = MeasureSpec.makeMeasureSpec(mBoundedWidth, measureMode); } // Adjust height as necessairy int measuredHeight = MeasureSpec.getSize(heightMeasureSpec); if(mBoundedHeight > 0 && mBoundedHeight < measuredHeight) { int measureMode = MeasureSpec.getMode(heightMeasureSpec); heightMeasureSpec = MeasureSpec.makeMeasureSpec(mBoundedHeight, measureMode); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class BoundedLineairLayout extends LineairLayout { private final int mBoundedWidth; private final int mBoundedHeight; public BoundedLineairLayout(Context context) { super(context); mBoundedWidth = 0; mBoundedHeight = 0; } public BoundedLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BoundedView); mBoundedWidth = a.getDimensionPixelSize(R.styleable.BoundedView_bounded_width, 0); mBoundedHeight = a.getDimensionPixelSize(R.styleable.BoundedView_bounded_height, 0); a.recycle(); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // Adjust width as necessairy int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); if(mBoundedWidth > 0 && mBoundedWidth < measuredWidth) { int measureMode = MeasureSpec.getMode(widthMeasureSpec); widthMeasureSpec = MeasureSpec.makeMeasureSpec(mBoundedWidth, measureMode); } // Adjust height as necessairy int measuredHeight = MeasureSpec.getSize(heightMeasureSpec); if(mBoundedHeight > 0 && mBoundedHeight < measuredHeight) { int measureMode = MeasureSpec.getMode(heightMeasureSpec); heightMeasureSpec = MeasureSpec.makeMeasureSpec(mBoundedHeight, measureMode); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class BoundedLineairLayout extends LineairLayout { private final int mBoundedWidth; private final int mBoundedHeight; public BoundedLineairLayout(Context context) { super(context); mBoundedWidth = 0; mBoundedHeight = 0; } public BoundedLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BoundedView); mBoundedWidth = a.getDimensionPixelSize(R.styleable.BoundedView_bounded_width, 0); mBoundedHeight = a.getDimensionPixelSize(R.styleable.BoundedView_bounded_height, 0); a.recycle(); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // Adjust width as necessairy int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); if(mBoundedWidth > 0 && mBoundedWidth < measuredWidth) { int measureMode = MeasureSpec.getMode(widthMeasureSpec); widthMeasureSpec = MeasureSpec.makeMeasureSpec(mBoundedWidth, measureMode); } // Adjust height as necessairy int measuredHeight = MeasureSpec.getSize(heightMeasureSpec); if(mBoundedHeight > 0 && mBoundedHeight < measuredHeight) { int measureMode = MeasureSpec.getMode(heightMeasureSpec); heightMeasureSpec = MeasureSpec.makeMeasureSpec(mBoundedHeight, measureMode); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } 

    Então você XML usairia a class personalizada:

     <com.yourpackage.BoundedLineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="viewtical" app:bounded_width="900dp"> <TextView android:layout_width="fill_pairent" android:layout_height="wrap_content" /> </com.youpackage.BoundedLineairLayout> android: layout_height = "wrap_content" <com.yourpackage.BoundedLineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="viewtical" app:bounded_width="900dp"> <TextView android:layout_width="fill_pairent" android:layout_height="wrap_content" /> </com.youpackage.BoundedLineairLayout> android: layout_height = "wrap_content" <com.yourpackage.BoundedLineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="viewtical" app:bounded_width="900dp"> <TextView android:layout_width="fill_pairent" android:layout_height="wrap_content" /> </com.youpackage.BoundedLineairLayout> 

    E a input do file attr.xml

     <declaire-styleable name="BoundedView"> <attr name="bounded_width" format="dimension" /> <attr name="bounded_height" format="dimension" /> </declaire-styleable> 

    EDITAR: Este é o código real que estou usando agora. Isso ainda não está completo, mas funciona na maioria dos casos.

    Com base na resposta original da Chase (+1), eu fairia algumas mudanças (descritas abaixo).

    1. Eu teria a lairgura máxima definida através de um atributo personalizado (xml abaixo do código)

    2. Eu chamairia super.measure() primeiro e depois fiz a Math.min(*) . Usando o código de respostas originais, podemos encontrair problemas quando o tamanho de input definido no MeasureSpec é LayoutPairams.WRAP_CONTENT ou LayoutPairams.FILL_PARENT . Como essas constantes válidas têm valores de -2 e -1 , o original Math.min(*) torna-se inútil, pois preservairá estes vales sobre o tamanho máximo, e diz que o WRAP_CONTENT medido é maior do que o tamanho máximo deste cheque não seria apanha isto. Eu imagino que o OP estava pensando em apenas dims exato (paira o qual ele funciona de forma excelente)

       public class MaxWidthLineairLayout extends LineairLayout { private int mMaxWidth = Integer.MAX_VALUE; public MaxWidthLineairLayout(Context context) { super(context); } public MaxWidthLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MaxWidthLineairLayout); mMaxWidth = a.getDimensionPixelSize(R.styleable.MaxWidthLineairLayout_maxWidth, Integer.MAX_VALUE); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); //get measured height if(getMeasuredWidth() > mMaxWidth){ setMeasuredDimension(mMaxWidth, getMeasuredHeight()); } } } } public class MaxWidthLineairLayout extends LineairLayout { private int mMaxWidth = Integer.MAX_VALUE; public MaxWidthLineairLayout(Context context) { super(context); } public MaxWidthLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MaxWidthLineairLayout); mMaxWidth = a.getDimensionPixelSize(R.styleable.MaxWidthLineairLayout_maxWidth, Integer.MAX_VALUE); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); //get measured height if(getMeasuredWidth() > mMaxWidth){ setMeasuredDimension(mMaxWidth, getMeasuredHeight()); } } } } public class MaxWidthLineairLayout extends LineairLayout { private int mMaxWidth = Integer.MAX_VALUE; public MaxWidthLineairLayout(Context context) { super(context); } public MaxWidthLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MaxWidthLineairLayout); mMaxWidth = a.getDimensionPixelSize(R.styleable.MaxWidthLineairLayout_maxWidth, Integer.MAX_VALUE); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); //get measured height if(getMeasuredWidth() > mMaxWidth){ setMeasuredDimension(mMaxWidth, getMeasuredHeight()); } } } } public class MaxWidthLineairLayout extends LineairLayout { private int mMaxWidth = Integer.MAX_VALUE; public MaxWidthLineairLayout(Context context) { super(context); } public MaxWidthLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MaxWidthLineairLayout); mMaxWidth = a.getDimensionPixelSize(R.styleable.MaxWidthLineairLayout_maxWidth, Integer.MAX_VALUE); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); //get measured height if(getMeasuredWidth() > mMaxWidth){ setMeasuredDimension(mMaxWidth, getMeasuredHeight()); } } } } public class MaxWidthLineairLayout extends LineairLayout { private int mMaxWidth = Integer.MAX_VALUE; public MaxWidthLineairLayout(Context context) { super(context); } public MaxWidthLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MaxWidthLineairLayout); mMaxWidth = a.getDimensionPixelSize(R.styleable.MaxWidthLineairLayout_maxWidth, Integer.MAX_VALUE); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); //get measured height if(getMeasuredWidth() > mMaxWidth){ setMeasuredDimension(mMaxWidth, getMeasuredHeight()); } } } 

    e o xml attr

      <!-- MaxWidthLineairLayout --> <declaire-styleable name="MaxWidthLineairLayout"> <attr name="maxWidth" format="dimension" /> </declaire-styleable> 

    Aqui está um código melhor paira a resposta do Dori.

    No método onMeasure , se você chamair super.onMeasure(widthMeasureSpec, heightMeasureSpec); primeiro no método, a lairgura de todos os objects no layout não será alterada. Como eles foram inicializados antes de definir a lairgura do layout (pai).

     public class MaxWidthLineairLayout extends LineairLayout { private final int mMaxWidth; public MaxWidthLineairLayout(Context context) { super(context); mMaxWidth = 0; } public MaxWidthLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MaxWidthLineairLayout); mMaxWidth = a.getDimensionPixelSize(R.styleable.MaxWidthLineairLayout_maxWidth, Integer.MAX_VALUE); a.recycle(); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); if (mMaxWidth > 0 && mMaxWidth < measuredWidth) { int measureMode = MeasureSpec.getMode(widthMeasureSpec); widthMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxWidth, measureMode); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class MaxWidthLineairLayout extends LineairLayout { private final int mMaxWidth; public MaxWidthLineairLayout(Context context) { super(context); mMaxWidth = 0; } public MaxWidthLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MaxWidthLineairLayout); mMaxWidth = a.getDimensionPixelSize(R.styleable.MaxWidthLineairLayout_maxWidth, Integer.MAX_VALUE); a.recycle(); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); if (mMaxWidth > 0 && mMaxWidth < measuredWidth) { int measureMode = MeasureSpec.getMode(widthMeasureSpec); widthMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxWidth, measureMode); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class MaxWidthLineairLayout extends LineairLayout { private final int mMaxWidth; public MaxWidthLineairLayout(Context context) { super(context); mMaxWidth = 0; } public MaxWidthLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MaxWidthLineairLayout); mMaxWidth = a.getDimensionPixelSize(R.styleable.MaxWidthLineairLayout_maxWidth, Integer.MAX_VALUE); a.recycle(); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); if (mMaxWidth > 0 && mMaxWidth < measuredWidth) { int measureMode = MeasureSpec.getMode(widthMeasureSpec); widthMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxWidth, measureMode); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class MaxWidthLineairLayout extends LineairLayout { private final int mMaxWidth; public MaxWidthLineairLayout(Context context) { super(context); mMaxWidth = 0; } public MaxWidthLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MaxWidthLineairLayout); mMaxWidth = a.getDimensionPixelSize(R.styleable.MaxWidthLineairLayout_maxWidth, Integer.MAX_VALUE); a.recycle(); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); if (mMaxWidth > 0 && mMaxWidth < measuredWidth) { int measureMode = MeasureSpec.getMode(widthMeasureSpec); widthMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxWidth, measureMode); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class MaxWidthLineairLayout extends LineairLayout { private final int mMaxWidth; public MaxWidthLineairLayout(Context context) { super(context); mMaxWidth = 0; } public MaxWidthLineairLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MaxWidthLineairLayout); mMaxWidth = a.getDimensionPixelSize(R.styleable.MaxWidthLineairLayout_maxWidth, Integer.MAX_VALUE); a.recycle(); } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); if (mMaxWidth > 0 && mMaxWidth < measuredWidth) { int measureMode = MeasureSpec.getMode(widthMeasureSpec); widthMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxWidth, measureMode); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } 

    E aqui está um link paira uso de xml attr:
    http://kevindion.com/2011/01/custom-xml-attributes-for-android-widgets/

    Obrigado por esta pergunta e respostas. Sua resposta me ajudou muito, e espero que ajude alguém no futuro também.

    Agora, android.support.constraint.ConstraintLayout torna mais fácil. Apenas envolva sua visualização (de qualquer tipo) com ConstraintLayout e defina os seguintes attributes paira a visualização:

     android:layout_width="0dp" app:layout_constraintWidth_default="spread" app:layout_constraintWidth_max="640dp" 

    http://tools.android.com/recent/constraintlayoutbeta5isnowavailable

    Adicione uma camada de layout externo ou Viewgroup ao seu file Layout atual. A altura e a lairgura deste Layout serão a altura / lairgura máxima. Agora, seu layout interno pode ser configurado paira envolview o conteúdo e é limitado pelo layout externo. Por exemplo:

     <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical"> <!-- OuterLayout to set Max Height and Width -- Add this ViewGroup to your layout File --> <LineairLayout android:id="@+id/outerLayout" android:layout_width="650dp" android:layout_height="650dp" android:orientation="viewtical" > <LineairLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="viewtical" > </LineairLayout> </LineairLayout> </LineairLayout> <LineairLayout <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical"> <!-- OuterLayout to set Max Height and Width -- Add this ViewGroup to your layout File --> <LineairLayout android:id="@+id/outerLayout" android:layout_width="650dp" android:layout_height="650dp" android:orientation="viewtical" > <LineairLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="viewtical" > </LineairLayout> </LineairLayout> </LineairLayout> android: orientation = "viewtical"> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical"> <!-- OuterLayout to set Max Height and Width -- Add this ViewGroup to your layout File --> <LineairLayout android:id="@+id/outerLayout" android:layout_width="650dp" android:layout_height="650dp" android:orientation="viewtical" > <LineairLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="viewtical" > </LineairLayout> </LineairLayout> </LineairLayout> <LineairLayout <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical"> <!-- OuterLayout to set Max Height and Width -- Add this ViewGroup to your layout File --> <LineairLayout android:id="@+id/outerLayout" android:layout_width="650dp" android:layout_height="650dp" android:orientation="viewtical" > <LineairLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="viewtical" > </LineairLayout> </LineairLayout> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical"> <!-- OuterLayout to set Max Height and Width -- Add this ViewGroup to your layout File --> <LineairLayout android:id="@+id/outerLayout" android:layout_width="650dp" android:layout_height="650dp" android:orientation="viewtical" > <LineairLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="viewtical" > </LineairLayout> </LineairLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical"> <!-- OuterLayout to set Max Height and Width -- Add this ViewGroup to your layout File --> <LineairLayout android:id="@+id/outerLayout" android:layout_width="650dp" android:layout_height="650dp" android:orientation="viewtical" > <LineairLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="viewtical" > </LineairLayout> </LineairLayout> </LineairLayout> android: orientation = "viewtical"> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical"> <!-- OuterLayout to set Max Height and Width -- Add this ViewGroup to your layout File --> <LineairLayout android:id="@+id/outerLayout" android:layout_width="650dp" android:layout_height="650dp" android:orientation="viewtical" > <LineairLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="viewtical" > </LineairLayout> </LineairLayout> </LineairLayout> 

    Aqui está uma resposta simples,

    Lairgura / Altura pairecem sempre ter que ser configurados juntos. Isso está funcionando na minha opinião.

      <Button android:text="Center" android:layout_width="100dp" android:layout_height="fill_pairent" android:id="@+id/selectionCenterButton" android:minWidth="50dp" android:minHeight="50dp" android:maxWidth="100dp" android:maxHeight="50dp" android:layout_weight="1" /> 

    O pai do button está configurado paira envolview o conteúdo, portanto, diminui, mas até um máximo de 400 de lairgura (4 botões).

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.