2016-07-01 3 views
0
**item_my_message.xml** 

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@android:color/transparent"> 

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="72dp" 
    android:background="@drawable/my_message_style" 
    android:elevation="4dp" 
    android:padding="8dp"> 

    <TextView 
     android:id="@+id/textView_mymessge" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_toLeftOf="@+id/textView_time" 
     android:text="asdasd" 
     android:textColor="@color/colorPrimaryBackgorund" /> 

    <TextView 
     android:id="@+id/textView_time" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/textView_mymessge" 
     android:layout_alignParentRight="true" 
     android:background="@android:color/transparent" 
     android:text="12:00 pm" 
     android:paddingRight="6dp" 
     android:textColor="@color/colorHint" 
     android:textSize="12dp" /> 
</RelativeLayout> 
</RelativeLayout> 


package pruebas.integra.Activites; 

import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.support.design.widget.FloatingActionButton; 
import android.support.design.widget.Snackbar; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.WindowManager; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.ImageView; 
import android.widget.ListView; 
import android.widget.TextView; 

import java.util.ArrayList; 
import java.util.Calendar; 
import java.util.Locale; 
import java.util.TimeZone; 

import pruebas.integra.Adapters.MensajeAdapter; 
import pruebas.integra.Models.ConversationModel; 
import pruebas.integra.R; 

public class ChatConversationActivity extends AppCompatActivity { 
Context context; 
TextView textViewNombre; 
TextView textViewEstado; 
ImageView imgEstado; 
EditText mensaje; 
MensajeAdapter mensajeAdapter; 
Button btnEnviarMensaje; 
ArrayList<ConversationModel> mensajeChat; 
ListView listView; 
Calendar c; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_chat_conversation); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    context = this; 
    c = Calendar.getInstance(); 

    imgEstado = (ImageView) findViewById(R.id.imageView_state); 
    String nombre = getIntent().getExtras().getString("value"); 
    Boolean state = getIntent().getExtras().getBoolean("estado"); 
    textViewEstado = (TextView) findViewById(R.id.textView_state); 
    if (state == true) { 
     textViewEstado.setText("Conectado"); 
      textViewEstado.setTextColor(context.getResources().getColor(android.R.color.holo_green_light)); 
     imgEstado.setColorFilter((context.getResources().getColor(android.R.color.holo_green_light))); 

    } else { 
     textViewEstado.setText("Desconectado"); 
     textViewEstado.setTextColor(context.getResources().getColor(R.color.colorPrimaryBackgorund)); 
     imgEstado.setColorFilter(R.color.colorPrimaryBackgorund); 
    } 

    final TimeZone tz = TimeZone.getDefault(); 
    textViewNombre = (TextView) findViewById(R.id.txtchatNombre); 
    textViewNombre.setText(nombre); 

    btnEnviarMensaje = (Button) findViewById(R.id.btn_enviarmensaje); 
    mensajeChat = new ArrayList<ConversationModel>(); 
    listView = (ListView) findViewById(R.id.listView_mensajes_conversacion); 
    mensaje = (EditText) findViewById(R.id.editText_mensaje); 

    mensajeAdapter = new MensajeAdapter(context, mensajeChat); 
    listView.setAdapter(mensajeAdapter); 

    btnEnviarMensaje.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      if (mensaje.getText().toString() == null && mensaje.getText().toString() == " ") { 

      } else { 
       ConversationModel conversation = new ConversationModel(); 
       //mensaje.getText().append("\ud83d\ude01"); //EMOJI 
       conversation.setMensaje(mensaje.getText().toString()); 
       String temp = Integer.toString(c.get(Calendar.HOUR_OF_DAY)) + ":" + Integer.toString(c.get(Calendar.MINUTE)); 
       conversation.setTime(temp); 
       mensajeChat.add(conversation); 
       mensajeAdapter.notifyDataSetChanged(); 
       mensaje.setText(""); 
       listView.smoothScrollToPosition(mensajeAdapter.getCount()); 
      } 
     } 
    }); 

} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
     case android.R.id.home: 
      onBackPressed(); 
      break; 
    } 
    return super.onOptionsItemSelected(item); 
} 

@Override 
public void onBackPressed() { 
    finish(); 
} 

}содержания Wrap не работает

У меня есть элемент, который я использую для чата, дело в том, что содержание обертки не работает, сама планировка остается на определенную ширине не по его содержанию я, кажется, не понимаю, почему это так.

This is how it looks, it is supposed to wrap the content

+0

Поместите 'android: layout_width =" wrap_content "' в первый 'RelativeLayout' –

+0

он по-прежнему выглядит одинаково :( –

ответ

0

Я не в полной мере понять, что вы спрашиваете, но я думаю, что проблема для первого textView Вы

android:layout_alignParentLeft="true" 

И для второй один

android:layout_alignParentRight="true" 

для второй textView не использовать выровненную родительскую собственность Но использовать

android:layout_toRightOf="@+id/textView_mymessge" 

если вы хотите time справа от сообщения ИЛИ использования

android:layout_below="@+id/textView_mymessge" 

если вы хотите time ниже в сообщении.

0

Если указать wrap_content для view или ViewGroup, для которых вытяжка (в вашем случае его "@drawable/my_message_style") используются в качестве android:background, вида занимает размер изображения используется. Решение состоит в том, чтобы уменьшить размер выталкиваемого, который вы используете в качестве фона вашего RelativeLayout. Или вы можете просто использовать цвет, тем легче. Надеюсь, что это помогает

Смежные вопросы