I am trying to use an image as the background for my loading dialog. The dialog is supposed to be full screen, but all I get is this...
How can I make the dialog fill the screen so I don't have that white border?
Heres my layout xml...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/locating"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/kumalocating">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="LOCATING OFFERS IN YOUR AREA"
android:textAlignment="center"
android:textAppearance="#style/TextAppearance.AppCompat.Large"
android:textColor="#android:color/white"
android:textSize="30sp"
android:textStyle="bold" />
</RelativeLayout>
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminateDrawable="#drawable/loader_1" />
</RelativeLayout>
and my class...
public class SpinnerDialog extends DialogFragment {
private static String message;
public SpinnerDialog() {
// use empty constructors. If something is needed use onCreate's
message = null;
}
public static SpinnerDialog spinnerWithCustomMessage(String msg) {
SpinnerDialog d = new SpinnerDialog();
message = msg;
return d;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fill_dialog, container);
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
Code to show:
spinnerDialog = SpinnerDialog.spinnerWithCustomMessage(getString(R.string.loading_message));
spinnerDialog.show(getFragmentManager(), null);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL,android.R.style.Theme_Black_NoTitleBar_Fullscreen);
}
Add above code inside the SpinnerDialog class!
Use this code in the Java class.
Dialog mydialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);
Edit
Add the following line in the SpinnerDialog.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_FRAME, android.R.style.Theme_Translucent_NoTitleBar);
}
Related
I created list using example: Material design suggestions for lists with avatar, text and icon
I want to have list with upcoming movies, so I need list with dynamically number of items. I dont understand and I dont know how I should do it.
There is my code for one item list:
public class FragmentOne extends Fragment {
TextView textView;
TextView textView2;
ImageView imageView;
public static FragmentOne newInstance() {
FragmentOne fragment = new FragmentOne();
return fragment;
}
public class MovieTask extends AsyncTask<Void, Void, MovieDb>{
#Override
protected MovieDb doInBackground(Void... voids) {
TmdbMovies movies = new TmdbApi("my_api_key").getMovies();
MovieDb movie = movies.getMovie(5335, "en");
return movie;
}
#Override
protected void onPostExecute(MovieDb movieDb) {
textView.setText(movieDb.getOriginalTitle());
textView2.setText(movieDb.getReleaseDate());
Glide.with(imageView).load("https://image.tmdb.org/t/p/w500" + movieDb.getPosterPath()).into(imageView);
}
}
#Override
public void onCreate(Bundle savedInstanceState) {
MovieTask mt = new MovieTask();
mt.execute();
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View returnView = inflater.inflate(R.layout.fragment_one, container, false);
textView = (TextView) returnView.findViewById(R.id.text);
textView2 = (TextView) returnView.findViewById(R.id.text2);
imageView = (ImageView) returnView.findViewById(R.id.list_icon);
return returnView;
}
}
and xml for that class
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="72dp"
tools:context=".FragmentOne">
<ImageView
android:id="#+id/list_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="16dp" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_toRightOf="#+id/list_icon"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingRight="16dp" />
<TextView
android:id="#+id/text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingRight="16dp" />
</LinearLayout>
</RelativeLayout>
I would personally suggest you to use Recyclerview and cardview to get this job done. You will need to create an adapter class for Recyclerview if you are not familiar with this.
Just check out this link -
https://www.journaldev.com/10024/android-recyclerview-android-cardview-example-tutorial
I'm trying to make an app that fetches a book list from an API and displays it on the master list and, upon clicking, it displays the details. It works fine with mobiles, but I can't get it to work with tablets and since there's no error I can't find out where I went wrong.
On tablets it renders as if on a phone instead of rendering the two pane view.
I'm using a single activity with fragments.
"Main" activity:
public class ItemListActivity extends AppCompatActivity {
public static FragmentManager fragmentManager;
private boolean isTwoPane = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_list);
determinePaneLayout();
fragmentManager = getSupportFragmentManager();
if(isTwoPane){
//fragmentManager.beginTransaction().add(R.id.master_dual, new ItemsListFragment()).commit();
fragmentManager.beginTransaction().add(R.id.flDetailContainer, new ItemDetailFragment()).commit();
fragmentManager.beginTransaction().add(R.id.fragmentContainer, new ItemsListFragment()).commit();
} else {
fragmentManager.beginTransaction().add(R.id.fragmentContainer, new ItemsListFragment()).commit();
}
}
private void determinePaneLayout() {
FrameLayout fragmentItemDetail = (FrameLayout) findViewById(R.id.flDetailContainer);
// If there is a second pane for details
if (fragmentItemDetail != null) {
isTwoPane = true;
}
}
Item List Fragment:
public class ItemsListFragment extends Fragment {
private ArrayList<Book> bookList;
private ArrayList<String> bookNames;
private ArrayAdapter<Book> bookArrayAdapter;
private ArrayAdapter<String> bookNamesAdapter;
private ApiInterface apiInterface;
private ListView lvItems;
private static final String bookKey = "newBook";
private static Book nBook;
public ItemsListFragment() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_items_list,
container, false);
return view;
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
lvItems = view.findViewById(R.id.lvItems);
bookNames = new ArrayList<>();
//bookNames.add(0, "Gabriel");
apiInterface = ApiClient.getApiClient().create(ApiInterface.class);
Call<ArrayList<Book>> call = apiInterface.getBooks();
call.enqueue(new Callback<ArrayList<Book>>() {
#Override
public void onResponse(Call<ArrayList<Book>> call, Response<ArrayList<Book>> response) {
bookList = new ArrayList<>();
bookList = response.body();
bookArrayAdapter = new ArrayAdapter<>(getContext(),
android.R.layout.simple_list_item_activated_1, bookList);
lvItems.setAdapter(bookArrayAdapter);
}
#Override
public void onFailure(Call<ArrayList<Book>> call, Throwable t) {
}
});
lvItems.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
nBook = bookList.get(i);
if(view.findViewById(R.id.flDetailContainer) != null){
ItemListActivity.fragmentManager.beginTransaction().replace(R.id.flDetailContainer, ItemDetailFragment.newInstance(nBook)).addToBackStack(null).commit();
} else {
ItemListActivity.fragmentManager.beginTransaction().replace(R.id.fragmentContainer, ItemDetailFragment.newInstance(nBook)).addToBackStack(null).commit();
}
}
});
}`
Item Detail Fragment:
public class ItemDetailFragment extends Fragment {
private static final String bookKey = "newBook";
private static Book nBook;
private TextView title;
private TextView isbn;
private TextView currency;
private TextView price;
private TextView author;
public static ItemDetailFragment newInstance(Book book) {
ItemDetailFragment fragment = new ItemDetailFragment();
Bundle args = new Bundle();
args.putSerializable(bookKey, book);
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
nBook = (Book)getArguments().getSerializable(bookKey);
Log.v("BundleOK", "BundleOK");
} else {
Log.v("Bundle Nulo", "Bundle nulo");
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate view
View view = inflater.inflate(R.layout.fragment_item_detail,
container, false);
// Return view
return view;
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
title = view.findViewById(R.id.tvTitle);
isbn = view.findViewById(R.id.tvIsbn);
currency = view.findViewById(R.id.tvCurrency);
price = view.findViewById(R.id.tvPrice);
author = view.findViewById(R.id.tvAuthor);
title.setText(nBook.getTitle());
isbn.setText("ISBN: " + nBook.getIsbn());
currency.setText("Currency: "+ nBook.getCurrency());
price.setText("Price: "+ String.valueOf((long)nBook.getPrice()/100));
author.setText("Autor: "+nBook.getAuthor());
}
XML for dual pane:
<?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:id="#+id/LinearLayout1"
android:showDividers="middle"
android:baselineAligned="false"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="#+id/fragmentItemsList"
android:name="gabrielgomes.studio.com.itemretrieve.ItemsListFragment"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
tools:layout="#layout/fragment_items_list" />
<View android:background="#000000"
android:layout_width="1dp"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="#+id/flDetailContainer"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" />
XML for the Main Activity (Item List Activity)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<FrameLayout
android:id="#+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
XML for the Item Detail Fragment:
<?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="match_parent" >
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="110dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:fontFamily="#font/baskervillebt"
android:gravity="center"
android:text="Item Title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tvIsbn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tvTitle"
android:layout_centerHorizontal="true"
android:layout_marginTop="44dp"
android:fontFamily="#font/baskervilleitalicbt"
android:text="Item Body"
android:textSize="16sp" />
<TextView
android:id="#+id/tvPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tvIsbn"
android:layout_centerHorizontal="true"
android:layout_marginTop="47dp"
android:fontFamily="#font/baskervilleitalicbt"
android:text="Price"
android:textSize="16sp" />
<TextView
android:id="#+id/tvCurrency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tvPrice"
android:layout_centerHorizontal="true"
android:fontFamily="#font/baskervilleitalicbt"
android:layout_marginTop="44dp"
android:text="Currency"
android:textSize="16sp" />
<TextView
android:id="#+id/tvAuthor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tvCurrency"
android:fontFamily="#font/baskervilleitalicbt"
android:layout_centerHorizontal="true"
android:layout_marginTop="45dp"
android:text="Author"
android:textSize="16sp" />
</RelativeLayout>
I've been cracking my head for 5 days now, so any help is really appreciated! I tried a number of tutorials and searched SO thoroughly but no go!
Cheers!
I believe you have two copies activity_item_list.xml layout file and one is res/layout/ folder and another one is in res/layout-sw600dp/ folder.
sw600dp --> Screen width above 600dp use this layout else if less than 600dp use default layout file.
And also you make sure keep same attribute ids same in both the layout files.
I'm doing a tourist places with VR with No sounds and No transition to other image. One of my friend tell me its not user friendly if every time he wants to view other image he needed to remove the phone to VR BOX to view again and he added put sounds to make it realistic.
Help me guys on how to add audio and transition in com.google.vr.sdk.widgets.pano I have no any idea how to make this.
Fragment
public class TW1 extends Fragment {
private VrPanoramaView panoWidgetView;
private ImageLoaderTask backgroundImageLoaderTask;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.activity_tw1, container,false);
panoWidgetView = (VrPanoramaView) v.findViewById(R.id.pano_view);
return v;
}
#Override
public void onPause() {
panoWidgetView.pauseRendering();
super.onPause();
}
#Override
public void onResume() {
panoWidgetView.resumeRendering();
super.onResume();
}
#Override
public void onDestroy() {
panoWidgetView.shutdown();
super.onDestroy();
}
private synchronized void loadPanoImage() {
ImageLoaderTask task = backgroundImageLoaderTask;
if (task != null && !task.isCancelled()) {
task.cancel(true);
}
VrPanoramaView.Options viewOptions = new VrPanoramaView.Options();
viewOptions.inputType = VrPanoramaView.Options.TYPE_STEREO_OVER_UNDER;
String panoImageName = "tw1.jpg";
task = new ImageLoaderTask(panoWidgetView, viewOptions, panoImageName);
task.execute(getActivity().getAssets());
backgroundImageLoaderTask = task;
}
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
loadPanoImage();
}
}
xml File
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:background="#ffffff">
<TextView
android:id="#+id/welcome_title"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_weight=".2"
android:text="#string/chocolate_hills"
android:textAlignment="center"
android:textStyle="bold"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
<com.google.vr.sdk.widgets.pano.VrPanoramaView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:id="#+id/pano_view"
android:layout_margin="5dip"
android:scrollbars="none"
android:contentDescription="#string/codelab_img_description" />
<TextView
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_weight=".2"
android:text="#string/chocolate_hills_location"
android:textStyle="bold"
android:textSize="12sp"
android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_weight="1"
android:text="#string/chocolate_hills_desc"
android:textColor="#000000"/>
</LinearLayout>
Red text came out a little small. Here is what it says:
Need to get the background color of the dialog so I can set the background of the "more info" textview to that same color. Need to do this programmatically because color of the dialog is different depending on API level.
Java code:
public class CityDetailDialog extends DialogFragment {
private SharedPreferences sharedPreferences;
private City mCity;
private LinearLayout mCityContainerLayout;
private ImageView mImageFlag;
private TextView mTextCity;
private ImageView mImageCity;
private ImageButton mButtonGoogleMaps;
private ImageButton mButtonWikipedia;
private TextView mMoreInfoTextView;
public CityDetailDialog() {
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container,
#Nullable Bundle savedInstanceState) {
sharedPreferences = getActivity().getSharedPreferences("settings", Context.MODE_PRIVATE);
return inflater.inflate(R.layout.dialog_city_detail, container, false);
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mCity = (City) getArguments().getSerializable("city");
mCityContainerLayout = (LinearLayout) view.findViewById(R.id.container_city_dialog);
mImageFlag = (ImageView) view.findViewById(R.id.flag_image);
mTextCity = (TextView) view.findViewById(R.id.city_name);
mImageCity = (ImageView) view.findViewById(R.id.city_image);
mButtonGoogleMaps = (ImageButton) view.findViewById(R.id.button_google_maps);
mButtonWikipedia = (ImageButton) view.findViewById(R.id.button_wikipedia);
mMoreInfoTextView = (TextView) view.findViewById(R.id.more_info_label);
mImageFlag.setImageResource(ResourceByNameRetriever.getDrawableResourceByName(mCity.
getCountryName(), getActivity()));
mTextCity.setText(ResourceByNameRetriever.getStringResourceByName(mCity.getCityName(),
getActivity()));
Picasso.with(getActivity()).load(mCity.getImageUrl()).into(mImageCity);
mButtonGoogleMaps.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent mapsIntent = new Intent(Intent.ACTION_VIEW);
mapsIntent.setData(Uri.parse("geo:" + mCity.getCoordinates()));
Intent chooser = Intent.createChooser(mapsIntent, getString(R.string.launch_maps));
startActivity(chooser);
}
});
mButtonWikipedia.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent wikiIntent = new Intent(Intent.ACTION_VIEW);
wikiIntent.setData(Uri.parse(mCity.getWikiUrl()));
Intent chooser = Intent.createChooser(wikiIntent, getString(R.string.launch_browser));
startActivity(chooser);
}
});
}
}
Based on the code in your xml file on github following changes need to be made to achieve the desired effect :
<LinearLayout
android:id="#+id/container_buttons"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal"
android:layout_below="#+id/relativeLayout">
.
.
.
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/relativeLayout">
<View
android:id="#+id/horizontal_divider1"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_centerInParent="true"
android:background="#color/gray"
android:layout_toLeftOf="#+id/more_info_label"
android:layout_toStartOf="#+id/more_info_label"/>
<TextView
android:id="#+id/more_info_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:padding="5dp"
android:text="#string/more_info"
android:textSize="18dp" />
<View
android:id="#+id/horizontal_divider2"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_centerInParent="true"
android:background="#color/gray"
android:layout_toRightOf="#+id/more_info_label"
android:layout_toEndOf="#+id/more_info_label"/>
</RelativeLayout>
i have a class which extends fragment class as below:
public class FragmentCreateGroup extends Fragment {
#Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
ImageView group=(ImageView)findViewById(R.id.group_image);//shows error here
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.fragment_creategroup, container,false);
}
}
which is associated to the following xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#string/cr_group_grpname_desc"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/group_image"
android:layout_width="139dp"
android:layout_height="144dp"
android:src="#drawable/background" />
<EditText
android:id="#+id/cr_group_grpname_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="37dp"
android:contentDescription="#string/cr_group_grpname_desc"
android:ems="10"
android:hint="#string/cr_group_grpname_hint"
android:inputType="text" >
<requestFocus />
</EditText>
<Button
android:id="#+id/cr_group_creategrp_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="42dp"
android:background="#drawable/greenbutton"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="#string/cr_group_creategrp_btn_label" />
</LinearLayout>
I tried to access the ImageView in the fragment layout using findViewById(). Since I didn't extend Activity class I was unable to perform this action. Is there any way to access the UI Elements from a non activity class? if any how to perform?
You need to get the view after you inflate it in onCreateView
public class FragmentCreateGroup extends Fragment {
private ImageView group;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_creategroup, container, false);
group = (ImageView) v.findViewById(R.id.group_image);
group.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
group.setImageDrawable(); // set image here
}
});
return v;
}
}