Ich fürchte des bringt dir nich viel. Am XML Code kann es ja eigentlich ja nicht liegen, oder ? Denn in Android Studio in der Designvorschau wurde das Bild ja korrekt angezeigt. Nur am Gerät nicht. Liegt wenn dann am Code oder an irgendetwas anderem. Ich kann ja mal was Posten.
Hier ist der Code von einem meiner Fragments:
Ich hoffe das hilft dir.
package com.mwittig98gmail.derberater.Fragments;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.mwittig98gmail.derberater.R;
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link ProvinzFragment.OnFragmentInteractionListener} interface
* to handle interaction events.
* Use the {@link ProvinzFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class ProvinzFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private OnFragmentInteractionListener mListener;
int landnummer;
View view;
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment ProvinzFragment.
*/
// TODO: Rename and change types and number of parameters
public static ProvinzFragment newInstance(String param1, String param2,int landnummer) {
ProvinzFragment fragment = new ProvinzFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
args.putInt("Landnummer",landnummer);
fragment.setArguments(args);
return fragment;
}
public ProvinzFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
landnummer = getArguments().getInt("Landnummer");
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_provinz, container, false);
mListener.ueberschrift("Provinz");
description(landnummer);
return view;
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
}
}
void description(int landnummer){
//Überschrift1
TextView textViewU1 = (TextView)view.findViewById(R.id.provinz_1);
textViewU1.setText(getString(R.string.Provinz_11));
//Text1
TextView textViewH1= (TextView)view.findViewById(R.id.provinz_2);
String s1 = getString(R.string.Provinz_12);
textViewH1.setText(s1);
//Text1Values
TextView textViewW1 = (TextView)view.findViewById(R.id.provinz_W1);
String sv1 = "Pannap"+"\u00E8"+"alene\n3.055.000";
textViewW1.setText(sv1);
//Überschrift2
TextView textViewU2 = (TextView)view.findViewById(R.id.provinz_3);
textViewU2.setText(getString(R.string.Provinz_13));
//Text2
TextView textViewH2= (TextView)view.findViewById(R.id.provinz_4);
String s2 = getString(R.string.Provinz_14);
textViewH2.setText(s2);
//Text2Values
TextView textViewW2 = (TextView)view.findViewById(R.id.provinz_W2);
String sv2 = "1%";
textViewW2.setText(sv2);
//
//Überschrift3
TextView textViewU3 = (TextView)view.findViewById(R.id.provinz_5);
textViewU3.setText(getString(R.string.Provinz_15));
//Text3
TextView textViewH3= (TextView)view.findViewById(R.id.provinz_6);
String s3 = getString(R.string.Provinz_16);
textViewH3.setText(s3);
//Text3Values
TextView textViewW3 = (TextView)view.findViewById(R.id.provinz_W3);
String sv3 = "1%";
textViewW3.setText(sv3);
//
//Überschrift4
TextView textViewU4 = (TextView)view.findViewById(R.id.provinz_7);
textViewU4.setText(getString(R.string.Provinz_17));
//Text4
TextView textViewH4= (TextView)view.findViewById(R.id.provinz_8);
String s4 = getString(R.string.Provinz_18);
textViewH4.setText(s4);
//Text4Values
TextView textViewW4 = (TextView)view.findViewById(R.id.provinz_W4);
String sv4 = "1%";
textViewW4.setText(sv4);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p/>
* See the Android Training lesson <a href=
*
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void ueberschrift(String s);
}
}
— geändert am 15.08.2015, 11:20:02