Based on this article, I've tried to build a ViewFlipper with multiple RelativeLayouts.
When proceeding as written in article (only change the height), I got (as expected) a ViewFlipper normally displayed :
My xml :
<ViewFlipper
android:id="#+id/view_flipper"
android:layout_width="fill_parent"
android:layout_height="200dp" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/img1" />
<TextView
style="#style/ImageTitle"
android:text="Test test" />
</RelativeLayout>
</ViewFlipper>
Style:
<style name="ImageTitle">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">50dp</item>
<item name="android:layout_alignParentBottom">true</item>
<item name="android:background">#99000000</item>
<item name="android:gravity">center</item>
<item name="android:maxLines">2</item>
<item name="android:textColor">#fff</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">18sp</item>
<item name="android:typeface">sans</item>
</style>
Then I've tried do generate RelativeLayout programmatically with the code below :
public void generateViewForFlipper(String url, int id, String text){
//new RelativeLayout
RelativeLayout relativeLayout = new RelativeLayout(this);
//Params for the RelaviteLayout
final ViewFlipper.LayoutParams frameLayoutLayoutParams = new ViewFlipper.LayoutParams(
ViewFlipper.LayoutParams.MATCH_PARENT,ViewFlipper.LayoutParams.MATCH_PARENT);
//ImageView
ImageView imageView = new ImageView (this);
imageView.setImageDrawable(getResources().getDrawable(R.drawable.img1));
imageView.setScaleType(ScaleType.CENTER_INSIDE);
imageView.setAdjustViewBounds(true);
// Params for the ImageView
final RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT );
//Application title
TextView textView = (TextView)getLayoutInflater().inflate(R.layout.tvtemplate, null);
textView.setText(text);
// Params for application title
final RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, 50);
mViewFlipper.addView(relativeLayout, frameLayoutLayoutParams);
relativeLayout.addView(imageView,imageParams);
relativeLayout.addView(textView,textParams);
}
tvtemplate.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/ImageTitle" />
Result screen :
As you can see, text is not aligned to the bottom, not "match_parent", and picture is not cropped..
Thank you
Related
I have the following SearchView implementation in the xml, the text entry has been cut from the top as shown in the below image. No matter what textSize I am putting, nothing changes.
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="32dp"
android:gravity="center_vertical"
android:layout_marginTop="10dp">
<SearchView
android:id="#+id/search_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="12sp"/>
</LinearLayout>
You can achieve this using a theme:
in styles.xml
<style name="AppSearchView" parent="Widget.AppCompat.SearchView" >
<item name="android:textSize">60sp</item>
</style>
And using a SearchView
<android.support.v7.widget.SearchView
android:id="#+id/searchView"
android:layout_width="350dp"
app:theme="#style/AppSearchView" // use app:theme not in style
android:layout_height="80dp"
android:layout_marginTop="15dp"/>
try this one
you have to pass your SearchView and textSize in this method
private void setSearchviewTextSize(SearchView searchView, int fontSize) {
try {
AutoCompleteTextView autoCompleteTextViewSearch = (AutoCompleteTextView) searchView.findViewById(searchView.getContext().getResources().getIdentifier("app:id/search_src_text", null, null));
if (autoCompleteTextViewSearch != null) {
autoCompleteTextViewSearch.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
} else {
LinearLayout linearLayout1 = (LinearLayout) searchView.getChildAt(0);
LinearLayout linearLayout2 = (LinearLayout) linearLayout1.getChildAt(2);
LinearLayout linearLayout3 = (LinearLayout) linearLayout2.getChildAt(1);
AutoCompleteTextView autoComplete = (AutoCompleteTextView) linearLayout3.getChildAt(0);
autoComplete.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
}
} catch (Exception e) {
LinearLayout linearLayout1 = (LinearLayout) searchView.getChildAt(0);
LinearLayout linearLayout2 = (LinearLayout) linearLayout1.getChildAt(2);
LinearLayout linearLayout3 = (LinearLayout) linearLayout2.getChildAt(1);
AutoCompleteTextView autoComplete = (AutoCompleteTextView) linearLayout3.getChildAt(0);
autoComplete.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
}
}
update your XML also
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<SearchView
android:id="#+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"/>
</LinearLayout>
sv= (SearchView) findViewById(R.id.search_view);
TextView searchText = (TextView)
sv.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchText.setTextSize(TypedValue.COMPLEX_UNIT_SP,12);
We can directly change in theme.xml
It will affect in whole application, where it has an search view.
Eg,
<item name="colorControlHighlight">#color/colorAccent</item>
<item name="colorControlNormal">#android:color/black</item>
<item name="android:editTextColor">#android:color/white</item>
<item name="android:textColorHint">#android:color/white</item>
<item name="android:textSize">30sp</item>
</style>
I need to customize Google Plus Sign in Button And Facebook Login Button like image below
As far as i know, Facebook Login Button make width and height by text size and padding
to change Google Sign in button i used the below method :
private void setGooglePlusButton(SignInButton signInButton, String buttonText) {
// ExceptionHelpers.dLog("GOOGLE_PLUS_TAG", "Child Count : "+signInButton.getChildCount());
signInButton.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
for (int i = 0; i < signInButton.getChildCount(); i++) {
View v = signInButton.getChildAt(i);
// ExceptionHelpers.dLog("GOOGLE_PLUS_TAG", "Type Of Child : "+v.getClass().getName());
if (v instanceof TextView) {
TextView tv = (TextView) v;
tv.setText(buttonText);
tv.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
tv.setBackgroundResource(R.drawable.google_background_drawable);
tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.facebook_compound_drawable, 0, 0, 0);
int padding = (int) getResources().getDimension(R.dimen.header_padding);
int drawablePadding = (int) getResources().getDimension(R.dimen.header_padding);
tv.setPadding(padding, padding, padding, padding);
tv.setCompoundDrawablePadding(drawablePadding);
tv.setTextColor(getResources().getColor(R.color.white_color));
tv.setTextSize(getResources().getDimension(R.dimen.font_title));
return;
}
}
}
and Facebook Login Button Style :
<style name="FacebookLoginButton">
<item name="android:layout_marginTop">#dimen/adapter_mark_padding</item>
<item name="android:layout_marginBottom">#dimen/adapter_mark_padding</item>
<item name="android:padding">#dimen/header_padding</item> <!-- #dimen/adapter_mark_padding -->
<item name="android:textSize">#dimen/font_title</item>
<item name="android:textColor">#color/white_color</item>
<item name="android:background">#drawable/facebook_background_drawable</item>
<item name="android:drawableLeft">#drawable/facebook_compound_drawable</item>
<item name="android:drawablePadding">#dimen/header_padding</item>
</style>
Output is :
<ImageView
android:id="#+id/fb_new_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#mipmap/ic_launcher" />
<RelativeLayout
android:id="#+id/fb_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone">
<com.facebook.login.widget.LoginButton
android:id="#+id/login_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
Put the code of login Facebook code in the click listener of the ImageView
it will work
for Facebook you need to use style:
<style name="FacebookLoginButton">
<item name="android:textSize">15dp</item>
<item name="android:textAllCaps">false</item>
<item name="android:layout_gravity">center</item>
<item name="android:textColor">#color/colorWhite</item>
<item name="android:paddingLeft">13dp</item>
<item name="colorButtonNormal">#color/colorAccent</item>
<item name="android:paddingTop">11dp</item>
<item name="android:paddingBottom">11dp</item>
<item name="android:layout_marginLeft">4dp</item>
<item name="android:layout_marginRight">5dp</item>
</style>
Apply the style like this
<com.facebook.login.widget.LoginButton
xmlns:facebook="http://schemas.android.com/apk/res-auto"
android:id="#+id/login_button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
style="#style/FacebookLoginButton"
facebook:com_facebook_login_text="#string/login_facebook"
facebook:com_facebook_logout_text="#string/login_facebook"
android:elevation="2dp"
/>
as for google you can use a normal button with your wanted style
<Button
android:id="#+id/button_googlePlus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/login_google"
android:background="?attr/selectableItemBackground"
android:textColor="#color/colorWhite"
android:textAllCaps="false"
android:textSize="15dp"
android:drawableLeft="#drawable/ic_google"
android:paddingLeft="40dp"
android:paddingRight="40dp"
/>
I am using PopupWindow, which is working fine, but the problem is after inflating the layout view that is shown with black border.
final PopupWindow popupWindow = new PopupWindow(context);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.pop_up_window_menu_layout, null);
popupWindow.setContentView(view);
pop_up_window_menu_layout.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/solid_white"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:text="SAVE"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="#color/black"
android:textSize="#dimen/txt_size_sliding_list" />
I've tried to remove border by using popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)), but problem is still same.
Can anyone tell me how to remove unwanted black border?
I don't see any border around my popup windows, but I do set them up slightly different than you. Hopefully this points you in the right direction.
popup_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#f5f5f5"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btn_close"
android:text="Close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/main_view"
tools:context=".MainActivity">
<Button
android:id="#+id/btn_popup"
android:text="Popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/txt_text"
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
MainActivity.java
public class MainActivity extends ActionBarActivity implements View.OnClickListener {
View popupView;
Button btnPopup;
Button btnClose;
PopupWindow popupWindow;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
popupView = getLayoutInflater().inflate(R.layout.popup_view, null);
btnClose = (Button) popupView.findViewById(R.id.btn_close);
btnClose.setOnClickListener(this);
popupWindow = new PopupWindow(popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
btnPopup = (Button) findViewById(R.id.btn_popup);
btnPopup.setOnClickListener(this);
}
#Override
public void onClick(View v) {
if (v.getId() == R.id.btn_popup) {
popupWindow.showAtLocation(findViewById(R.id.main_view), Gravity.NO_GRAVITY, 100, 200);
//popupWindow.showAsDropDown(btnPopup, 10, 10);
} else if (v.getId() == R.id.btn_close) {
popupWindow.dismiss();
}
}
}
If you getting a black border this means that the default background is set.
this is how you remove it :
popup.setBackgroundDrawable(null);
Try this
Just try this and let me know..
Be sure to create your Pop-up window referencing your custom theme:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="DialogTheme" parent="android:Theme.Dialog">
<!-- Fill the screen -->
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<!-- No backgrounds and No titles , and no Window Floating -->
<item name="android:windowBackground">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<!-- Set background what you want-->
<item name="android:background">#ff0000</item>
</style>
</resources>
This is because you are sending context inside popup window constructor. -
final PopupWindow popupWindow = new PopupWindow(context);
Change this by popup window view -
View popupView = getLayoutInflater().inflate(R.layout.popup_view, null);
PopupWindow popupWindow = new Pop
i am trying to display the text in the center of button, but text is not completely fit in the button like that
here is i am trying to display V and W and space is also there but it just not fit in. Help Please
text of style is like this
<style name="textstyle">
<item name="android:textSize">15sp</item>
<item name="android:gravity">center</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#000000</item>
</style>
size of button is decided on run time
box = new Button(context);
box.setTextAppearance(context, R.style.input_box_textstyle);
Drawable image = context.getResources().getDrawable(R.drawable.inputbox);
box.setBackgroundDrawable(image);
.
.
.
if(size <= n)
{
Log.v("textsize..", width+"");
p = new LinearLayout.LayoutParams(width, height);
}
else
{
p = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 60);
p.weight = 1;
}
box.setLayoutParams(p);
isSet = false;
Issue solve by setting the
box.setIncludeFontPadding(false);
box.setPadding(0, 0, 0, 0);
I hope this must be your xml
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:layout_below="#id/imagetitle"
android:orientation="horizontal">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="V" android:id="#+id/previous" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="W" android:id="#+id/next" />
</LinearLayout>
RelativeLayout.ALIGN_PARENT_RIGHT not work. (((
it is my Android-Function.
She added new message to a stage.
I do not understand.
Why my code does not work correctly
private void addMessageToStage(Message message) {
LinearLayout scrollChatMessagesOutput = (LinearLayout) findViewById(R.id.chatMessagesOutput);
LayoutInflater layoutInflater = getLayoutInflater();
View view = layoutInflater.inflate(R.layout.chat_single_message, null, false);
TextView messageTextView = (TextView) view.findViewById(R.id.singleChatMessageTextView);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
if (messagesAlignId % 2 == 0) {
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
messageTextView.setBackgroundResource(R.drawable.chat_input_message_shape);
} else {
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
messageTextView.setBackgroundResource(R.drawable.chat_output_message_shape);
}
messageTextView.setText(Html.fromHtml("<b><u>" + message.getMessage() + "<font color=\"#cccccc\" size=\"4px\">" + "\n" + message.getTime() + "</font></b></u>"));
RelativeLayout messageAlignLayout = new RelativeLayout(this);
messageAlignLayout.addView(view, params);
scrollChatMessagesOutput.addView(messageAlignLayout);
}
It is chat_single_message.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/chatMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0" >
<TextView
android:id="#+id/singleChatMessageTextView"
style="#style/singleChatMessageTextStyle" />
</LinearLayout>
It is singleChatMessageTextStyle.
<style name="singleChatMessageTextStyle" parent="#android:style/TextAppearance.Small">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginBottom">10dp</item>
<item name="android:layout_marginLeft">5dp</item>
<item name="android:layout_marginRight">5dp</item>
<item name="android:padding">3dp</item>
<item name="android:layout_weight">0.7</item>
<item name="android:textColor">#000000</item>
<item name="android:typeface">sans</item>
<item name="android:textSize">12sp</item>
</style>
Consider using two different layouts:
A layout with the text on the left, chat_single_message_left.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/chatMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0" >
<TextView
android:id="#+id/singleChatMessageTextView"
style="#style/singleChatMessageTextStyle" />
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:visibility="invisible" />
</LinearLayout>
A similar layout with the text on the right, chat_single_message_right.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/chatMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0" >
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:visibility="invisible" />
<TextView
android:id="#+id/singleChatMessageTextView"
style="#style/singleChatMessageTextStyle" />
</LinearLayout>
And you should use a ListView to display each message rather than a ScrollView, ListView's are much faster for big conversations.