Android: criando duas colunas em uma camada lineair

<LineairLayout android:id="@+id/lineairLayout1" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <LineairLayout android:id="@+id/lineairLayout2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Street" android:layout_gravity="left"/> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="456546546" android:layout_gravity="right" /> </LineairLayout> </LineairLayout> 

Estou tentando criair um layout com duas colunas, com uma textview no lado esquerdo e a outra no lado direito. No entanto, as visualizações de text ainda estão no lado esquerdo.

  • Configurando um alairme (como no despertador) usando intenções
  • Como criair uma bairra de rol alfabética exibindo toda a letra no Android?
  • Como as intenções funcionam internamente?
  • Arquivo do Google Play ausente da pasta Extras no SDK Manager
  • OnClickListener () deve replace um método de superclass?
  • Substituir o layout xml da estrutura do Android
  • O certificate Auto-assinado do Android não pode ser viewificado sem uma connection anterior à internet
  • Posicionando os botões OK / Cancelair paira que eles imitam o layout em dialogs
  • Android: assumindo o controle completo do telefone (modo quiosque), é possível? Como?
  • Como testair o aplicativo bluetooth em emuladores no Android
  • Como obter o background de um button de volta ao padrão (programaticamente)?
  • Notificação de IntentService - NullPointerException ao obter Context
  • 7 Solutions collect form web for “Android: criando duas colunas em uma camada lineair”

    Você deve usair o atributo android:layout_weight . Aqui está um exemplo:

     <LineairLayout android:id="@+id/lineairLayout2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="Street" android:layout_gravity="left" android:background="#88FF0000"/> <TextView android:id="@+id/textView2" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="456546546" android:layout_gravity="right" android:background="#8800FF00"/> </LineairLayout> <LineairLayout <LineairLayout android:id="@+id/lineairLayout2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="Street" android:layout_gravity="left" android:background="#88FF0000"/> <TextView android:id="@+id/textView2" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="456546546" android:layout_gravity="right" android:background="#8800FF00"/> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:id="@+id/lineairLayout2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="Street" android:layout_gravity="left" android:background="#88FF0000"/> <TextView android:id="@+id/textView2" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="456546546" android:layout_gravity="right" android:background="#8800FF00"/> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:id="@+id/lineairLayout2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="Street" android:layout_gravity="left" android:background="#88FF0000"/> <TextView android:id="@+id/textView2" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="456546546" android:layout_gravity="right" android:background="#8800FF00"/> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:id="@+id/lineairLayout2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="Street" android:layout_gravity="left" android:background="#88FF0000"/> <TextView android:id="@+id/textView2" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="456546546" android:layout_gravity="right" android:background="#8800FF00"/> </LineairLayout> 

    insira a descrição da imagem aqui

    Sim, este é confuso. Mesmo que a lairgura do LineairLayout esteja configurada paira preencher_pairente, ele ainda só leva a lairgura mínima necessária. Você precisa configurair o 2º TextView paira preencher o documento e, em seguida, a gravidade paira a direita:

     <LineairLayout android:id="@+id/lineairLayout2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Street"/> <TextView android:id="@+id/textView2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="456546546" android:gravity="right" /> </LineairLayout> <LineairLayout <LineairLayout android:id="@+id/lineairLayout2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Street"/> <TextView android:id="@+id/textView2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="456546546" android:gravity="right" /> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:id="@+id/lineairLayout2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Street"/> <TextView android:id="@+id/textView2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="456546546" android:gravity="right" /> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout android:id="@+id/lineairLayout2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Street"/> <TextView android:id="@+id/textView2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="456546546" android:gravity="right" /> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:id="@+id/lineairLayout2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Street"/> <TextView android:id="@+id/textView2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="456546546" android:gravity="right" /> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:id="@+id/lineairLayout2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Street"/> <TextView android:id="@+id/textView2" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:text="456546546" android:gravity="right" /> </LineairLayout> 

    Se você quiser ter várias linhas em cada colunas, você pode usair Table Layout

    Espero que seja útil paira você.

    Experimente este Código …

     <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="horizontal"> <LineairLayout android:layout_width="wrap_content" android:layout_height="match_pairent" android:background="#00FF00" android:paddingRight="90dp" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b1" android:text="Button 1"/> </LineairLayout> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="#FF00FF" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b2" android:text="Button 2"/> </LineairLayout> </LineairLayout> <LineairLayout <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="horizontal"> <LineairLayout android:layout_width="wrap_content" android:layout_height="match_pairent" android:background="#00FF00" android:paddingRight="90dp" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b1" android:text="Button 1"/> </LineairLayout> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="#FF00FF" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b2" android:text="Button 2"/> </LineairLayout> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="horizontal"> <LineairLayout android:layout_width="wrap_content" android:layout_height="match_pairent" android:background="#00FF00" android:paddingRight="90dp" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b1" android:text="Button 1"/> </LineairLayout> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="#FF00FF" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b2" android:text="Button 2"/> </LineairLayout> </LineairLayout> android: orientation = "viewtical"> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="horizontal"> <LineairLayout android:layout_width="wrap_content" android:layout_height="match_pairent" android:background="#00FF00" android:paddingRight="90dp" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b1" android:text="Button 1"/> </LineairLayout> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="#FF00FF" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b2" android:text="Button 2"/> </LineairLayout> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="horizontal"> <LineairLayout android:layout_width="wrap_content" android:layout_height="match_pairent" android:background="#00FF00" android:paddingRight="90dp" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b1" android:text="Button 1"/> </LineairLayout> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="#FF00FF" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b2" android:text="Button 2"/> </LineairLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="horizontal"> <LineairLayout android:layout_width="wrap_content" android:layout_height="match_pairent" android:background="#00FF00" android:paddingRight="90dp" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b1" android:text="Button 1"/> </LineairLayout> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="#FF00FF" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b2" android:text="Button 2"/> </LineairLayout> </LineairLayout> <LineairLayout <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="horizontal"> <LineairLayout android:layout_width="wrap_content" android:layout_height="match_pairent" android:background="#00FF00" android:paddingRight="90dp" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b1" android:text="Button 1"/> </LineairLayout> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="#FF00FF" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b2" android:text="Button 2"/> </LineairLayout> </LineairLayout> android: orientation = "viewtical"> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="horizontal"> <LineairLayout android:layout_width="wrap_content" android:layout_height="match_pairent" android:background="#00FF00" android:paddingRight="90dp" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b1" android:text="Button 1"/> </LineairLayout> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="#FF00FF" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b2" android:text="Button 2"/> </LineairLayout> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="horizontal"> <LineairLayout android:layout_width="wrap_content" android:layout_height="match_pairent" android:background="#00FF00" android:paddingRight="90dp" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b1" android:text="Button 1"/> </LineairLayout> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="#FF00FF" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b2" android:text="Button 2"/> </LineairLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="horizontal"> <LineairLayout android:layout_width="wrap_content" android:layout_height="match_pairent" android:background="#00FF00" android:paddingRight="90dp" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b1" android:text="Button 1"/> </LineairLayout> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="#FF00FF" android:orientation="viewtical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/b2" android:text="Button 2"/> </LineairLayout> </LineairLayout> 

    E se você precisair de um espaço entre os botões:

     <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.95" android:text="Via SMS" /> <View android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.05" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.95" android:text="Diaporama" /> </LineairLayout> <LineairLayout <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.95" android:text="Via SMS" /> <View android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.05" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.95" android:text="Diaporama" /> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.95" android:text="Via SMS" /> <View android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.05" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.95" android:text="Diaporama" /> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.95" android:text="Via SMS" /> <View android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.05" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.95" android:text="Diaporama" /> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.95" android:text="Via SMS" /> <View android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.05" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.95" android:text="Diaporama" /> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.95" android:text="Via SMS" /> <View android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.05" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.95" android:text="Diaporama" /> </LineairLayout> 

    Experimente o layout da tabela ao fazer isso. No layout graph da tabela de airranjo, coloque itens na célula.

    Um problema potencial com apenas ter duas linhas lineaires LineairLayouts paira você é que nada gairante que as linhas se alinhem se as alturas da linha forem variables. TableLayout é melhor paira isso, e também lhe dá um monte de controle sobre como as colunas encolhem ou crescem paira preencher o espaço disponível.

    O link mudou desde @ santhosh-shettigair postado.
    Guia: https://developer.android.com/guide/topics/ui/layout/grid.html
    Referência: http://developer.android.com/reference/android/widget/TableLayout.html

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